Search code examples
pythonpython-3.xiplan

Python check for online ip addresses


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


Solution

  • 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.