Program not giving output
I need some assistance I am trying to break and IP header down in Python
and I have my code written, but I am not getting anything back on the
screen. I do not know what I am missing. Suggestions are welcome:
import struct
from collections import OrderedDict
def tcpheader (rawTCP):
#Using dict for the dictionary
tcp=OrderedDict.fromkeys({})
tcp['ttl']=struct.unpack('!H',rawTCP[8:12]) [0] # H! is to unpack the
hex file and then search for the portion specified
tcp['totalength']=struct.unpack('!H',rawTCP[0:20]) [0]
tcp['sourceip']=struct.unpack('!H',rawTCP[12:16]) [0]
tcp['destip']=struct.unpack('!H',rawTCP[16:20]) [0]
return tcp #this is the proper way to break the loop and return
def tcpdecode():
infile=open ('C:/users/jwattenbarger/desktop/ip.dd', 'rb') #this is
opening the ip.dd file
rawTCP=infile.read(40)
#IPraw=infile.read (40)
tcp=tcpheader(rawTCP)
#tcp=tcpheader(IPraw)
print ("ttl:", tcp['ttl']) #these are printing the data
print ("totalength:", tcp['totalength'])
print ("sourceip:", tcp['sourceip'])
print ("destip:", tcp['destip'])
Print ("Temp")
for i in tcp: #associating i with tcp
print (i, "\t",tcp[i]) #printing tcp to the screen in a table
No comments:
Post a Comment