ARP扫描macOS / Raspbian / Python结果的差异

问题描述 投票:0回答:1

[在一些教程的帮助下,我编写了一个Python脚本,列出了网络中设备的网络详细信息。

但是,如果我运行Python脚本,我只会检测某些设备。在搜索某些设备(例如iOS设备)时,我已经看到没有响应(但偶尔会被检测到),但是奇怪的是:

  • macOS(Catalina,10.15.2)确实找到了带有“ arp -a”的设备
  • Raspbian(10,破坏者)在执行“ arp -a”时也找到了许多设备,但没有找到iOS设备
  • Python(3 / 2.7)找不到Raspbian和macOS可以找到的Arduino设备,我从Mac运行Python脚本。
  • 在Pi上运行Python脚本的确也给了我Arduino设备。

我使用Scapy处理Python中的ARP消息(基于本教程:https://www.thepythoncode.com/article/building-network-scanner-using-scapy:]

def find_devices(gateway):
    _ip_items = gateway.split(".")
    target_ip = "%s.%s.%s.%s" % (_ip_items[0], _ip_items[1], _ip_items[2], "0/24")


    # IP Address for the destination
    # create ARP packet
    arp = ARP(pdst=target_ip)
    # create the Ether broadcast packet
    # ff:ff:ff:ff:ff:ff MAC address indicates broadcasting
    ether = Ether(dst="ff:ff:ff:ff:ff:ff")

    # stack them
    packet = ether/arp
    result = srp(packet, timeout=3, verbose=0)[0]

    # a list of clients, we will fill this in the upcoming loop
    clients = []

    for sent, received in result:
        # for each response, append ip and mac address to `clients` list
        clients.append({'ip': received.psrc, 'mac': received.hwsrc})
        print("{:16}    {}".format(received.psrc, received.hwsrc))

当然,我可以直接使用ARP -A(例如,从Python执行ARP并解析结果),但是我对Raspberry Pi似乎能够检测到比Python代码更多的设备并且macOS可以检测到更多设备的原因更加好奇(他们是在作弊并使用bonjour吗?),但是为什么两者都检测到了Arduino(带有MQTT发布/子代码的Nano 33 IoT板),而macOS上的脚本却没有检测到它们。

python scapy arp
1个回答
0
投票

我实际上发现,当我有可能将超时值设置为更大的值(例如15)时,我什至可以得到iOS设备和Arduino设备。它仍然比macOS慢得多(arp -a给出即时响应),但是他们可能是从某些缓存或其他东西中提取它的?它确实会从Python代码中生成我在arp -a中看到的所有设备,即使它变得非常慢。

© www.soinside.com 2019 - 2024. All rights reserved.