无法发送数据包(Errno 9:错误的文件描述符)

Can't send packets (Errno 9: Bad file descriptor)

嗨,我是 Python 和 Scapy 的初学者。当我尝试在基本第 2 层数据包上使用 sendp() 时,出现回溯错误。

使用 Python 3.8 和来自 https://scapy.readthedocs.io/en/latest/installation.html#platform-specific-instructions

的最新开发版 Scapy

这就是我输入 Python shell:

import scapy
from scapy.all import *
a=Ether()/IP(dst="www.google.ca")/ICMP()/"Hello world"
sendp(a)

这是错误信息:

Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    sendp(a)
  File "C:\Users\hoang\AppData\Local\Programs\Python\Python38-32\lib\site-packages\scapy-git_archive.dev304758016-py3.8.egg\scapy\sendrecv.py", line 336, in sendp
    results = __gen_send(socket, x, inter=inter, loop=loop,
  File "C:\Users\hoang\AppData\Local\Programs\Python\Python38-32\lib\site-packages\scapy-git_archive.dev304758016-py3.8.egg\scapy\sendrecv.py", line 296, in __gen_send
    os.write(1, b".")
OSError: [Errno 9] Bad file descriptor

正如@furas 所指出的,这确实是您的控制台的问题(IDLE?)。 Scapy 尝试显示数据包已发送,但失败了。

您可以随时使用

sendp(p, verbose=False)

禁用日志,从而解决该问题。

但是我必须说,如果 os.write(1, ..) 是当时唯一的选择,那么现在它有点过时了。这可能会在上游得到修复。