Scapy 无法嗅探所有接口

Scapy cannot sniff from all interfaces

我正在尝试使用 scapy 从所有接口中嗅探,但是当我尝试提供接口列表时,出现以下错误:

sniff(iface=["eth1","eth2"], prn=lambda x: x.sniffed_on+": "+x.summary())
File "C:\Users\a\AppData\Local\Programs\Python\Python39\lib\site-packages\scapy\sendrecv.py", line 1263, in sniff
sniffer._run(*args, **kwargs)
File "C:\Users\a\AppData\Local\Programs\Python\Python39\lib\site-packages\scapy\sendrecv.py", line 1127, in _run
sniff_sockets[L2socket(type=ETH_P_ALL, iface=iface,
File "C:\Users\a\AppData\Local\Programs\Python\Python39\lib\site-packages\scapy\arch\libpcap.py", line 376, in __init__
self.ins = open_pcap(iface, MTU, self.promisc, 100,
File "C:\Users\a\AppData\Local\Programs\Python\Python39\lib\site-packages\scapy\arch\windows\__init__.py", line 704, in open_pcap
return _orig_open_pcap(iface_network_name, *args, **kargs)
File "C:\Users\a\AppData\Local\Programs\Python\Python39\lib\site-packages\scapy\arch\libpcap.py", line 231, in __init__
self.iface = create_string_buffer(device.encode("utf8"))

AttributeError: 'list' 对象没有属性 'encode'

下面是我的脚本:

def main():
    sniff(iface=["Ethernet","Wi-Fi"], prn=lambda x: x.sniffed_on+": "+x.summary())

def process_packet(packet):
    print(packet)

有人能告诉我这里有什么问题吗?或者如何从 all/multiple 接口嗅探并使用函数 process_packet?

进行处理

我的 scapy 版本是 windows 10 x64

上的 2.4.5

scapy 有问题。它在 the issue #3191:

中描述

Basic sniff capture using multiple interfaces.

When passing a list (or dict) of interfaces, Scapy raises an exception (see below).

[...]

Thanks for reporting the issue. That is indeed a regression!

他们确定了 the commit 并且似乎特定于版本 2.4.5。

试试2.4.4版本。如果你使用 pip 你可以试试:

pip install scapy==2.4.4