Scapy,IndexError:未找到[dot11]

发布于 2025-02-05 17:35:17 字数 1067 浏览 3 评论 0原文

我正在尝试使用SCAPY发送HTTP响应。我嗅出一个请求,然后尝试制造答复。我以此问题的问题为基础。 。这是引起问题的代码:

import scapy.all as scapy
from scapy.layers.http import HTTPRequest
from scapy.layers.dot11 import RadioTap
from scapy.layers.dot11 import Dot11
packets = scapy.sniff(count=30)
    for i in range(len(packets)):
        if packets[i].haslayer(HTTPRequest):
            pkt = packets[i]
            dot11_frame = RadioTap()/Dot11(
                type = "Data",
                FCfield = "from-DS",
                addr1 = pkt[scapy.Dot11].addr2,
                addr2 = pkt[scapy.Dot11].addr1,
                addr3 = pkt[scapy.Dot11].addr1,
                )

在我嗅到数据包并获取所需的所有信息之后,我要做另一个人所做的事情,问题是我继续遇到此错误,并定义dot11_frame,indexError:层[dot11]找不到,这发生在行addr1 = pkt [scapy.dot11] .addr2时发生。我什至没有像一些的答案。那么如何解决此错误?

I am trying to send a HTTP response using scapy. I sniff out an request and then attempt to fabricate a response. I am basing this off the code in this question. Here is the code that is causing problems:

import scapy.all as scapy
from scapy.layers.http import HTTPRequest
from scapy.layers.dot11 import RadioTap
from scapy.layers.dot11 import Dot11
packets = scapy.sniff(count=30)
    for i in range(len(packets)):
        if packets[i].haslayer(HTTPRequest):
            pkt = packets[i]
            dot11_frame = RadioTap()/Dot11(
                type = "Data",
                FCfield = "from-DS",
                addr1 = pkt[scapy.Dot11].addr2,
                addr2 = pkt[scapy.Dot11].addr1,
                addr3 = pkt[scapy.Dot11].addr1,
                )

After I sniff the packet and get all the information required I do what the other guy did, and the problem is that I keep on getting this error with the part defining dot11_frame, IndexError: Layer [Dot11] not found, this happens when the line addr1 = pkt[scapy.Dot11].addr2 is run. I have not even done a wildcard import like some answers suggested. So how do I fix this error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

居里长安 2025-02-12 17:35:17

首先,您可能是指pkt [dot11],而不是[scapy.dot11],因为您导入了名称dot11

其次,似乎您捕获的数据包不包含dot11层。例如,如果您从非Wi-Fi接口捕获数据包,或者是从不配置为监视器接口的Wi-Fi接口中捕获数据包。

为了帮助您调试问题,可以在分配pkt变量后添加print(pkt.command())

另外,您可能想在认真使用Scapy之前学习一些Python。例如,而不是:

for i in range(len(packets)):
    if packets[i].haslayer(HTTPRequest):
        pkt = packets[i]
        [...]

您想写:

for pkt in packets:
    if HTTPRequest not in pkt:
        continue
    [...]

希望这会有所帮助!

First, you probably mean pkt[Dot11], not [scapy.Dot11], as you imported the name Dot11.

Second, it seems that the packet you are capturing do not contain a Dot11 layer. This will happen, for example, if you capture packets from a non-Wi-Fi interface, or from a Wi-Fi interface that is not configured as a monitor interface.

To help you debug your problem, you could add a print(pkt.command()) just after assigning the pkt variable.

Also, you probably want to learn a bit of Python before using Scapy seriously. For example, rather than:

for i in range(len(packets)):
    if packets[i].haslayer(HTTPRequest):
        pkt = packets[i]
        [...]

You want to write:

for pkt in packets:
    if HTTPRequest not in pkt:
        continue
    [...]

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文