NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import socket
import struct
import time
import subprocess, os , signal

def send_msg(sock, msg):

msg = struct.pack('>I', len(msg)) + msg
sock.sendall(msg)

def sendFlowTCP(dst="10.0.32.3",sport=5000,dport=5001,ipd=1,duration=0):

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
#s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
#s.setsockopt(socket.IPPROTO_TCP, socket.TCP_MAXSEG, 1500)

s.bind(('', sport))

try:
reconnections = 5
while reconnections:
try:
s.connect((dst, dport))
break
except:
reconnections -=1
print "TCP flow client could not connect with server... Reconnections left {0} ...".format(reconnections)
time.sleep(0.5)

#could not connect to the server
if reconnections == 0:
return

totalTime = int(duration)

startTime = time.time()
i = 0
time_step = 1
iterator=0
while (time.time() - startTime <= totalTime):
if time.time() - startTime <= 0.50*totalTime:
s.setsockopt(socket.SOL_IP,socket.IP_TTL,64)
send_msg(s,"HELLO")
elif time.time() - startTime <= 0.75*totalTime:
if iterator == 0:
s.setsockopt(socket.SOL_IP,socket.IP_TTL,64)
send_msg(s,"HELLO")
else:
s.setsockopt(socket.SOL_IP,socket.IP_TTL,2)
send_msg(s,"HELLO")
iterator= 1 - iterator
else:
s.setsockopt(socket.SOL_IP,socket.IP_TTL,64)
send_msg(s,"HELLO")

i +=1
next_send_time = startTime + i * ipd
time.sleep(max(0,next_send_time - time.time()))

except socket.error:
pass

finally:
s.close()


def recvFlowTCP(dport=5001,**kwargs):

"""
Lisitens on port dport until a client connects sends data and closes the connection. All the received
data is thrown for optimization purposes.
:param dport:
:return:
"""

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
# s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

s.bind(("", dport))
s.listen(1)
conn = ''
buffer = bytearray(4096)
try:
conn, addr = s.accept()
while True:
#data = recv_msg(conn)#conn.recv(1024)
if not conn.recv_into(buffer,4096):
break

finally:
if conn:
conn.close()
else:
s.close()
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.