You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python中scapy.srp1返回发送数据包而非设备响应的问题

问题:Scapy srp1返回发送的数据包而非设备响应

我在Windows 10系统的Python 3.10环境中,尝试使用scapy包通过原始以太网与嵌入式设备通信。调用srp1函数发送二层原始数据包时,返回值是我发送的原始数据包,而非设备的响应。

代码示例

from scapy.arch.windows import *
from scapy.all import *

def get_if():
        for info in get_windows_if_list():
                if (info['description'] == 'Linksys USB3GIGV1'):
                        for k,v in info.items():
                                if (k == 'name'):
                                        name = v
                                elif (k == 'mac'):
                                        mac = v
        return (name, mac)

(interface, src_addr) = get_if()
etherType = 0x1234
dst_addr = b"\xfc\xee\xdd\xcc\xbb\xaa"
payload = bytearray.fromhex("2a0000001234567820200100") + bytearray(34)
packet = Ether(src=src_addr, dst=dst_addr, type=etherType)/payload
rsp = srp1(packet, iface=interface)
hexdump(packet)
hexdump(rsp)

现象说明

用Wireshark监控目标接口时,能看到正确的发送包和设备的响应包,但脚本输出如下:

Begin emission:
Finished sending 1 packets.

Received 1 packets, got 1 answers, remaining 0 packets

0000 FC EE DD CC BB AA 24 F5 A2 F1 BE C1 12 34 2A 00 ......$......4*.
0010 00 00 12 34 56 78 20 20 01 00 00 00 00 00 00 00 ...4Vx ........
0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0030 00 00 00 00 00 00 00 00 00 00 00 00 ............

0000 FC EE DD CC BB AA 24 F5 A2 F1 BE C1 12 34 2A 00 ......$......4*.
0010 00 00 12 34 56 78 20 20 01 00 00 00 00 00 00 00 ...4Vx ........
0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0030 00 00 00 00 00 00 00 00 00 00 00 00 ............

可以看到,返回的响应与发送的数据包完全一致。

另外,我有一段基于npcap的Java代码可以和该设备正常通信,因此问题肯定出在Scapy或Python的使用方式上。


内容的提问来源于stack exchange,提问作者Rick Ball

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 09:15:54