-1

嗨,我想在 FREEBSD 上通过 python、ipv6 嗅探数据包。

我很难尝试使用谷歌搜索来获取信息,但对于 freebsd 示例来说没有任何内容。

下面的代码不起作用,因为有人说 bsd 系统不支持

套接字.PF_PACKET。

有没有人有任何链接来帮助我?

s = socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.htons(3))
s.setsockopt(socket.SOL_SOCKET, IN.SO_BINDTODEVICE, struct.pack("%ds"%(len("em1")+1,),"em1"))
while condition:
    pkt = s.recvfrom(1500)
    addToQueue(filter(pkt))
4

1 回答 1

2

I would take a look at using a Python wrapper for libpcap. libpcap is a C library that is used to sniff packets and process pcap dumps. This is the same library that Wireshark uses. It comes standard with OSX and can be installed on most Linux distributions.

There exists a number of Python wrapper for this:

Make sure to avoid any implementations that are pure Python, as they are not able to do packet sniffing.

于 2012-10-22T16:25:48.877 回答