Created
July 25, 2011 18:03
-
-
Save d1b/1104732 to your computer and use it in GitHub Desktop.
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 socket | |
f = open('/proc/net/arp', 'r') | |
data = f.readlines() | |
#print data | |
f.close() | |
def get_hostname(ip): | |
try: | |
return socket.gethostbyaddr(ip)[0] | |
except socket.herror, e: | |
#print ip, repr(e), | |
return None | |
for line in data[1:]: | |
ipaddr = line.split(" ")[0] | |
mac = line.index(":") | |
if mac < 0: | |
print ipaddr, "unknown..." | |
continue | |
end_mac = line[mac:].index(" ") + mac | |
hostname = get_hostname(ipaddr) | |
print (hostname, ipaddr), line[mac-2: end_mac] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment