view other computers on the network programatically in Python
Is it possible to view other devices that are on the same network in Python (or any programming language for that matter)?
Edit: For clarification, what I'd like to do (just to start out) is to display a list of devices connected and their local IP addresses. So on my router, it'll show the info:
family_pc, 192.168.1.2 work_laptop, 192.168.1.3
I开发者_开发问答'd like to retrieve this info.
What are you trying to do exactly?
nmap
is a pretty common tool for scanning networks, which seems like you want to do. There is also a python-nmap package which lets you use nmap directly from within Python with ease.
Please be more detailed so we can give you a better answer, cheers.
You have a couple of options here.
You can run port scans over the entire network address space, but that's pretty wasteful and unfriendly. I don't recommend it.
A nicer approach would be to query for devices using a service discovery protocol like DNS-SD / Zeroconf (aka Bonjour). Most Linux and Mac systems will respond, as will many network printers and other network devices. Windows systems don't ship with a DNS-SD agent, but one can be installed.
A pure python implementation of DNS-SD is available here. I have used it on Linux, MacOS, and Windows.
If you prefer a Microsoft approach, you can try the discovery features of UPnP, though I can't vouch for how well it works or how many systems will respond.
If you don't mind using a little third party software you could use Netresview which works nicely on windows systems, avoid reinventing the wheel and all that. You could this kind of thing.
os.system('NetResView.exe /DisplayComputers 1 /RetrieveIPAddresses /stext ipfile')
my_file = open('ipfile')
for line in my_file :
print myfile.readline()
精彩评论