Created
July 15, 2014 01:19
-
-
Save kjseefried/360cf8c7636295f42469 to your computer and use it in GitHub Desktop.
Example of using the Python socket lib to sniff packets.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
from struct import * | |
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP) | |
#'!BBBHHHHHHBBBBH5s5s' | |
while True: | |
packet= s.recvfrom(65565) | |
print packet | |
packet =packet[0] | |
print "\n",packet | |
header=packet[0:26] | |
print "\n",header | |
iph = unpack('!BHBBHHBBBBBHH4s4s' , header) | |
print "\nall header: ",iph | |
version_ihl=iph[0] | |
print "\nVersion_ihl: ",version_ihl | |
version =version_ihl >>4 | |
print "\nVersion :" ,version | |
ttl=iph[5] | |
print"\nTTL: ",ttl | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment