Python                                                          Home : www.sharetechnote.com

 

 

 

 

Python - Socket

 

NOTE 1 : All the examples in this page are written in Python 3.x. It may not work if you use Pyton 2.x

NOTE 2 : All the examples in this page are assumed to be written/run on Windows 7 unless specifically mentioned. You MAY (or may not) need to modify the syntax a little bit if you are running on other operating system.

 

 

RAW Packet

 

< Sender >

 

s = socket.socket(socket.AF_INET, socket.SOCK_RAW,protocol_number)

....

s.sendto(UserData, (dstination_IP, 0))

 

 

< Reciever >

 

s = socket.socket(socket.AF_INET, socket.SOCK_RAW,protocol_number)

s.bind((IP_Reciever,0))

....

recvBytes = s.recv(NumberOfBytes)

 

 

Examples >