0

I'm trying to somehow get a list of all connected devices on a network, and then show their ip with it. I want it to show something like this:

computername - 192.168.0.0
computer2 - 192.168.100.43

I have tried nmap and after a long time I was able to use it but it wont work.

I'm using Python 3.6.5, Windows 8.1.

If anyone could answer, it would help a lot.

Edit: I did go here before, but I'm not sure how to list the names and ip using that method.

Cyclip
  • 11
  • 1
  • 2
  • 4

1 Answers1

0

You can use the command arp -a and scrape the results of os.popen:

import os, re
full_results = [re.findall('^[\w\?\.]+|(?<=\s)\([\d\.]+\)|(?<=at\s)[\w\:]+', i) for i in os.popen('arp -a')]
final_results = [dict(zip(['IP', 'LAN_IP', 'MAC_ADDRESS'], i)) for i in full_results]
final_results = [{**i, **{'LAN_IP':i['LAN_IP'][1:-1]}} for i in final_results]

Sample output:

[{'IP': '?', 'LAN_IP': '192.168.1.4', 'MAC_ADDRESS': '11:1a:ec:da:d4:ee'}, ...]

arp -a gives a full listing of all the devices on the network of the machine executing the command.

Ajax1234
  • 69,937
  • 8
  • 61
  • 102
  • arp -a doesn't give the names of the computers though, it gives: ip - physical - type I want it to show the name and ip. And that code doesn't work too (https://pastebin.com/THszrZfx) – Cyclip Jun 23 '18 at 16:37
  • `KeyError: 'LAN_IP'` – Sam May 09 '19 at 08:07