从这个问题继续。 https://stackoverflow.com/questions/9330686/parsing-pcap-in-python-2-6 我现在正在尝试执行打印摘要,但仍然不确定在我的最后一个论点中包含什么在打印摘要之前。请看下面的代码:
def run_example():
global total_packet_count, total_bytes_count, average_pkt_size
try:
sys.argv[1]
dmp_file = sys.argv[1]
fp_dmp_file = open(dmp_file)
except Exception as e:
print 'Error: please supply pcap filename!\n'
return
f = open('test1.pcap') try: sys.argv[1] dmp_file = sys.argv[1] file = open(dmp_file) except Exception as e: print 'Error: please provide pcap filename!\n' return
pcap = dpkt.pcap.Reader(file)
for ts, buf in pcap:
eth = dpkt.ethernet.Ethernet(buf)
ip = eth.data
tcp = ip.data
src_ip = socket.inet_ntoa(ip.src)
src_port = str(ip.data.sport)
dst_ip = socket.inet_ntoa(ip.dst)
dst_port = str(ip.data.dport)
if type(ip.data) == dpkt.tcp.TCP:
protocol = 'tcp'
elif type(ip.data) == dpkt.udp.UDP:
protocol = 'udp'
print_packet_info (ts, src_ip, src_port, dst_ip, dst_port, protocol, ip.len, ip.ttl)
print_summary(len (total_packet_count), len (total_bytes_count), len (average_pkt_size))
##fp_dmp_file.close()
如果名称== '主要':run_example()
我设法打印了数据包数据,但仍然无法打印摘要。我想我需要从全局计算值才能打印摘要。
任何帮助深表感谢