首页 > 解决方案 > arp -a 命令不返回本地网络中的所有计算机

问题描述

我正在尝试制作一个程序,该程序可以根据服务器输入的端口自动连接到本地网络中的计算机。现在,它似乎连接到本地网络中的“大多数”计算机,但似乎找不到我特别要找的那些,尽管它们在同一个 wifi 上。

这是连接方法:

def connect(self):
    devices = []
    for device in os.popen('arp -a'): devices.append(device)
    for ip in devices:
        b = re.findall(r"(?:\s|\A)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(?=\s|\Z)", ip)
        try:
            print(b[0])
            client_socket = socket.socket()
            client_socket.settimeout(3)
            client_socket.connect((b[0], self.port))
            if type(client_socket) != None:
                return client_socket
        except Exception as e:
            print(e)

出于某种原因,当它扫描时它只是没有给我 IP 地址('192.168.1.32')(合理 IP 地址的随机示例)。它只是...跳过。我不知道为什么。

有谁知道如何解决这个问题?任何事情都会不胜感激

标签: pythonsockets

解决方案


推荐阅读