SCAPY 发送数据包错误 OSError: [Errno 97] 协议不支持地址族

use*_*713 2 python sockets scapy

尝试使用以下方法发送数据包时遇到以下错误:

  • Ubuntu:发布 18.04
  • 蟒蛇:3.6.6
  • scapy 版本:2.4.0
>>> send(IP(dst="192.168.1.1")/ICMP())
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-2-8333be02b5c1> in <module>
----> 1 send(IP(dst="192.168.1.1")/ICMP())

~/scapy/lib/python3.6/site-packages/scapy/sendrecv.py in send(x, inter, loop, count, verbose, realtime, return_packets, socket, *args, **kargs)
    298      [socket=None]) -> None"""
    299     if socket is None
--> 300         socket = conf.L3socket(*args, **kargs)
    301     return __gen_send(socket, x, inter=inter, loop=loop, count=count, verbose=verbose,
    302                       realtime=realtime, return_packets=return_packets)

~/scapy/lib/python3.6/site-packages/scapy/arch/linux.py in __init__(self, iface, type, promisc, filter, nofilter, monitor)
    405     def __init__(self, type = ETH_P_ALL, filter=None, promisc=None, iface=None, nofilter=0):
    406         self.type = type
--> 407         self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
    408         self.ins.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 0)
    409         if iface:

/usr/lib/python3.6/socket.py in __init__(self, family, type, proto, fileno)
    142         # constructor of _socket.socket converts the given argument to an
    143         # integer automatically.
--> 144         _socket.socket.__init__(self, family, type, proto, fileno)
    145         self._io_refs = 0
    146         self._closed = False

OSError: [Errno 97] Address family not supported by protocol
Run Code Online (Sandbox Code Playgroud)

在全新安装的 Scapy 上有什么可能导致这种情况吗?

小智 8

如果您使用适用于 Linux 的 VM 或 Windows 子系统,则可能会发生这种情况。尝试标准安装,这为我解决了同样的问题。