【问题标题】:Can't send packets (Errno 9: Bad file descriptor)无法发送数据包(Errno 9:错误的文件描述符)
【发布时间】:2019-10-17 02:57:38
【问题描述】:

您好,我是 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

【问题讨论】:

  • 在 Linux 上我必须以管理员权限运行它(使用命令 sudo)。也许在 Windows 上是同样的问题 - 只有管理员可以访问 scapy 使用的套接字。
  • @furas 感谢您的建议!如果我在 CMD shell 中工作,我可以发送带有 scapy 的数据包。但是将 scapy 导入 Python Shell (IDLE) 仍然不允许我发送数据包,即使我以管理员身份运行它也是如此。
  • 所以问题是 IDLE,而不是代码。然后不要使用 IDLE,而是使用任何其他编辑器、IDE 或 python shell。

标签: python scapy


【解决方案1】:

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

您可以随时使用

sendp(p, verbose=False)

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-20
    • 1970-01-01
    • 1970-01-01
    • 2015-09-07
    • 1970-01-01
    • 1970-01-01
    • 2021-04-29
    • 1970-01-01
    相关资源
    最近更新 更多