python - 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 地址的随机示例)。它只是...跳过。我不知道为什么。
有谁知道如何解决这个问题?任何事情都会不胜感激
解决方案
推荐阅读
- c++ - 将多个设备传递给一个上下文是否意味着内核将被分发到两个设备?
- amazon-web-services - 如何使用 CLI 更新 AWS DynamoDB 中的嵌套项
- android - Android OnItemClickListener 和 OnClickListener
- c# - Visual Studio“生成单个文件”发布 - Serilog
- c# - 来自 WPF 的静默打印
- javascript - 通过字符索引标记文本
- mongodb - 使用nestjs在mongodb中保持时区偏移的时间
- django - 如何确定请求对象是从 Web 浏览器还是 REST API 调用发起的?
- javascript - 使用 redis/vue 发布键值
- node.js - 尽管在 Windows 10 (Chrome) 的 script-src 中定义了 script-src-elem,但仍被阻止