我的 pcap 文件是通过以下命令生成的:
cmd = """tshark -r "%s" -R "frame.time_relative >= %f" -w "%s" """ % (pcap_name, first_dns_query_time, normalized_pcap_name)
subprocess.Popen(cmd)
并且将标准化的 pcap 输入到pcap2har。我收到此错误:
Traceback (most recent call last):
File "main.py", line 65, in <module>
dispatcher = pcap.EasyParsePcap(filename=inputfile)
File "/path/to/pcap2har/pcap2har/pcap.py", line 80, in EasyParsePcap
ParsePcap(dispatcher, filename=filename, reader=reader)
File "/path/to/pcap2har/pcap2har/pcap.py", line 27, in ParsePcap
pcap = ModifiedReader(f)
File "/path/to/pcap2har/pcap2har/pcaputil.py", line 105, in __init__
raise ValueError, 'invalid tcpdump header'
ValueError: invalid tcpdump header
引发错误的部分pcaputil.py
是:
elif self.__fh.magic != dpkt.pcap.TCPDUMP_MAGIC:
raise ValueError, 'invalid tcpdump header'
对于我的 pcap(以及任何由 tshark 命令生成的 pcap),self.__fh.magic
is168627466
和dpkt.pcap.TCPDUMP_MAGIC
is 2712847316
。
我评论了引发异常的行,pcaputil.py
但之后我得到了这个:
Traceback (most recent call last):
File "main.py", line 65, in <module>
dispatcher = pcap.EasyParsePcap(filename=inputfile)
File "/path/to/pcap2har/pcap2har/pcap.py", line 80, in EasyParsePcap
ParsePcap(dispatcher, filename=filename, reader=reader)
File "/path/to/pcap2har/pcap2har/pcap.py", line 27, in ParsePcap
pcap = ModifiedReader(f)
File "/path/to/pcap2har/pcap2har/pcaputil.py", line 108, in __init__
self.dloff = dpkt.pcap.dltoff[self.__fh.linktype]
KeyError: 4294967295L