ValueError:以下代码的无效 tcpdump 标头错误。
import dpkt
f = open('a.pcap')
pcap = dpkt.pcap.Reader(f)
for (src, sport, dst, dport, data) in udp_iterator(pc):
if dport == 53:
dns = dpkt.dns.DNS(data)
if dns.opcode != dpkt.dns.DNS_QUERY:
print "A DNS packet was sent to the nameserver, but the opcode was %d instead of DNS_QUERY (this is a software error)" % dns.opcode
if dns.qr != dpkt.dns.DNS_Q:
print "A DNS packet was sent to the name server, but dns.qr is not 0 and should be. It is %d" % dns.qr
print "DNS Query was: ", dns.qd[0].name
print "ID is: ", dns.id
print "Hello Dns query is ", dns.qr
print "Hello Query Type is ", dns.qd[0].type , type_table[dns.qd[0].type]
print "Hello DNS Query was: ", dns.qd
帮助将不胜感激。pcap 是使用 mergecap 生成的,然后使用 dpkt 进行解析,但错误如下所示:
File "/usr/local/lib/python2.7/dist-packages/dpkt/pcap.py",
in __init__
raise ValueError('invalid tcpdump header')
ValueError: invalid tcpdump header