-1

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

ndurvasula
  • 185
  • 5
  • 18
  • It would help us if you would post the code you've already written and describe the specific problem in detail. – That1Guy Feb 05 '14 at 16:58

2 Answers2

1

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.

  • When I run this I get the following error:Traceback (most recent call last): File "C:/Python32/pynotifytest.py", line 4, in ip = f.findall( r'[0-9]+(?:\.[0-9]+){3}', s ) AttributeError: '_io.TextIOWrapper' object has no attribute 'findall' – ndurvasula Feb 05 '14 at 17:34
  • i changed your code to ip = re.findall(r'[0-9]+(?:\.[0-9]+){3}',f.read()). When I ran the program, ip's value was []. Then I printed f.read() before the re.findall line. f.read() returned an empty string. I don't think that arp -a works on my windows computer – ndurvasula Feb 05 '14 at 17:49
  • open cmd and write in arp -a to test – Theodor Solbjørg Feb 05 '14 at 21:02
  • http://andreasthirteen.files.wordpress.com/2012/11/arp.jpg I am not sure what windows version you have then – Theodor Solbjørg Feb 05 '14 at 21:11
  • I had to change my environment vars. f.findall still gives an error though – ndurvasula Feb 05 '14 at 21:25
  • @user3129956 There was a typo in the answer. It should have been `re.findall` where `re` is an imported module for regular expressions. – Bryce Guinta Nov 09 '16 at 21:33
0

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/

  • thank you for the suggestion, but I have seen this page and did not find it very useful – ndurvasula Feb 05 '14 at 17:03
  • okay, since what you are asking, searching for is on the low end of networking i suggest that you look at the socket class of phyton http://docs.python.org/2/library/socket.html – Theodor Solbjørg Feb 05 '14 at 17:06
  • do you have any suggestions as to how I could find all online devices connected to a lan network using socket? – ndurvasula Feb 05 '14 at 17:07
  • no that was more directed at host information. – Theodor Solbjørg Feb 05 '14 at 17:08
  • so what modules could I use to find this information? – ndurvasula Feb 05 '14 at 17:10
  • I am not to sure about python's native api, but on a lazy term, i would say call arp -a to get the ip address from command prompt, read them in to the application. alternatively i also found this: http://www.velocityreviews.com/forums/t319555-re-how-to-get-all-ip-addresses-in-python.html – Theodor Solbjørg Feb 05 '14 at 17:19
  • does this return the hostnames and ip addresses of every device connected to the lan network? – ndurvasula Feb 05 '14 at 17:25