Only using modules from the standard python 3 library, is it possible to find all online ip addresses and their hostnames in the same lan network that your computer is using? If so, can somebody put up a working implementation of this? I have been searching for hours and I have not been able to find an implementation of this.

Any implementations/suggestions would be deeply appreciated

I do not have any implementations of this project currently

有帮助吗?

解决方案

To find the locally connected ip address use arp -a and save to file.

import os
os.system('arp -a > ipaddresses.tmp')
f = open('ipaddresses.tmp', 'r')

now that we have a file that lists all the ip address we need to extract them using regex since there is alot of other junk in there.

ip = f.findall( r'[0-9]+(?:\.[0-9]+){3}', s )

and now you have an array of ip address that you can ping for information.

hope that helped.

其他提示

There are so many dependency on this question, first off i wanna point out that each OS has native calls for IP and hostname locations, linux, windows, osx, but i managed to dig up an article, thats seems to be generic. http://houseoflaudanum.com/navigate/snippets/discovering-local-ip-addresses-in-python/

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top