Python dpkt 数据包分析
我想用python dpkt这个工具,从pcap文件中找到时间戳;就像使用tcpdump -tttt这个选项一样,它可以给我提供数据包生成时的日期和时间的详细信息。
2 个回答
1
这可以通过导入datetime这个包来实现。
import dpkt
import datetime
for ts, buf in pcap:
eth=dpkt.ethernet.Ethernet()
//this is the method that is used to convert the epoch time to date
date1=**datetime.datetime.fromtimestamp(float(ts)).strftime('%d-%m-%Y')**
//rest of the code can go after this
1
如果你能在你的问题中提供一些代码示例,那就太好了。根据我的大致猜测,你可以试试下面这样的代码:
myPcap = open('test.pcap')
pcap = dpkt.pcap.Reader(myPcap)
for ts in pcap:
print ts