简体   繁体   English

获取网络上所有已连接的设备名称-Python

[英]Get all connected device name on the network - Python

I try to get all connected device name and IP on my network. 我尝试获取网络上所有已连接的设备名称和IP。

I've a raspberry pi and I want to use it as a "Network supervisor". 我有一个树莓派,我想将其用作“网络管理员”。 For example if a new device is connected I want to display its IP and name. 例如,如果连接了新设备,我想显示其IP和名称。

I tried some libraries like nmap and scapy but isn't really what I try to do. 我尝试了一些库,例如nmap和scapy,但这并不是我真正尝试做的。

Thanks for your help. 谢谢你的帮助。

You can get the nmap data into python by using subprocess 您可以使用子进程将nmap数据导入python

import subprocess
nmap = subprocess.Popen('nmap', stdout=subprocess.PIPE)
ipout = nmap.communicate()[0]

from there you can use basic python to strip down what you have in ipout and check if there are any differences and if so state those differences. 从那里,您可以使用基本的python剥离ipout中的内容,并检查是否存在任何差异,如果有,请声明这些差异。

Typo @ Scott's answer, ...stdout**=**subprocess.PIPE). 错字@ Scott的答案,... stdout ** = ** subprocess.PIPE)。 I dont have the rep to just comment. 我没有代表可以发表评论。

import subprocess
nmap = subprocess.Popen(('nmap'), stdout=subprocess.PIPE)
ipout = nmap.communicate()[

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

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