[英]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. 我需要一些帮助,我试图破坏Python的IP标头,并编写了代码,但屏幕上什么都没有回来。 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
Call tcpdecode()
; 调用
tcpdecode()
; just add the line: 只需添加以下行:
tcpdecode()
at the bottom of your module. 在模块底部。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.