简体   繁体   English

带有 scapy 的 ARP 数据包无应答

[英]ARP packets with scapy are unanswered

I'm building a network scanner with Python using Scapy.我正在使用 Scapy 构建一个带有 Python 的网络扫描仪。 I've been trying to send ARP packets but for some reason they don't get responded to.我一直在尝试发送 ARP 数据包,但由于某种原因它们没有得到响应。

#!/usr/bin/env python3

from scapy.all import *

def scan(ip):
    arp_request = ARP(pdst=ip)
    broadcast = Ether(dst="ff:ff:ff:ff:ff:ff")
    arp_request_broadcast = arp_request/broadcast
    answered_list = srp(arp_request_broadcast, timeout=2)[0]
    
    for element in answered_list:
        print(element[1].show())
    
scan("192.168.1.0/24")

Running it results in the following:运行它会产生以下结果:

[void@Void Network Scanner]$ sudo python3 tutorial_netscanner.py 
[sudo] password for void: 
Begin emission:
Finished sending 256 packets.
............................................................
Received 60 packets, got 0 answers, remaining 256 packets

The strange part is that if I run this from the scapy interactive shell it works and the arp packets do get answered.奇怪的是,如果我从 scapy 交互式 shell 运行它,它可以工作,并且 arp 数据包确实得到了回答。

arping("192.168.1.0/24")

Super confused as to why this isn't working, the code seems perfectly fine to me, if anyone could help me out that would be great.超级困惑为什么这不起作用,代码对我来说似乎非常好,如果有人可以帮助我,那就太好了。 Thank you.谢谢你。

arp_request/broadcast is incorrect. arp_request/broadcast不正确。 The outer-most protocols go on the left.最外层的协议 go 在左侧。 If you use Wireshark to see what's going on (the first thing you should do when something like this happens), you can see that it's not what you'd expect it to be:如果您使用 Wireshark 查看发生了什么(发生这种情况时您应该做的第一件事),您会发现它不是您所期望的:

Wireshark 行

It's essentially a malformed packet.它本质上是一个格式错误的数据包。 You need broadcast / arp_request ;你需要broadcast / arp_request although specifying the Ether layer is optional.尽管指定Ether层是可选的。 You can use simply ARP (and sr ).您可以简单地使用ARP (和sr )。

Use Wireshark.使用 Wireshark。 It's an invaluable tool.这是一个非常宝贵的工具。 You should only run it on networks that you have control over/permission to snoop, but it really is indispensable.你应该只在你可以控制/允许窥探的网络上运行它,但它确实是必不可少的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM