Skip to content

Instantly share code, notes, and snippets.

@mplewis
Created June 10, 2013 21:44
Show Gist options
  • Save mplewis/5752651 to your computer and use it in GitHub Desktop.
Save mplewis/5752651 to your computer and use it in GitHub Desktop.
quick and dirty python script (the best kind) to list all MACs on the LAN and their associated IPs
import os, time, subprocess
def run_command_silently(command):
with open(os.devnull, 'wb') as devnull:
subprocess.check_call(command.split(' '), stdout=devnull, stderr=subprocess.STDOUT)
run_command_silently('ping -c 1 255.255.255.255')
time.sleep(0.5)
arp_entries = subprocess.check_output(('arp','-na')).splitlines()
all_ip_and_macs = []
for entry in arp_entries:
ip_addr, rest = entry.split('(')[1].split(') at ')
mac_addr = rest.split(' on ')[0]
all_ip_and_macs.append((ip_addr, mac_addr))
for ip_mac_tuple in all_ip_and_macs:
print 'IP:', ip_mac_tuple[0], 'MAC:', ip_mac_tuple[1]
@taylortrimble
Copy link

This is pretty cool. I didn't run it, but awesome sauce for concept.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment