在python中使用dpkt时出错

2024-09-27 09:30:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写一些代码来解析python中的pcap文件,如下所示:

#!/usr/bin/env python
import socket
import dpkt
import sys
import pcap
pcapReader = dpkt.pcap.Reader(file("clients.pcap", "rb"))
for ts, data in pcapReader:
    ether = dpkt.ethernet.Ethernet(data)
    if ether.type != dpkt.ethernet.ETH_TYPE_IP: raise
    ip = ether.data
    src = socket.inet_ntoa(ip.src)
    dst = socket.inet_ntoa(ip.dst)
    print "%s -> %s" % (src, dst)

编译时,我收到以下错误消息::

^{pr2}$

感谢任何帮助。在


Tags: 文件代码importipsrcdatapcapsocket

热门问题