Created
June 10, 2013 21:44
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is pretty cool. I didn't run it, but awesome sauce for concept.