How can I get the MAC addresses of machines using python-nmap?
I'm using python-nmap to scan my local network, I can get the ip of several systems but not their MAC addresses.
How can I get the MAC addresses in the scan results?
nm = nmap.PortScanner()
a=nm.scan(hosts=cidr2, arguments='-sP')
for k,v in a['scan'].iteritems():
if str(v['status']['state']) == 'up':
number_thread += 1
print str(v)
try: print str(v['addresses']['ipv4']) + ' => ' + str(v['addresses']['mac'])
except: print str(v['addresses']['ipv4'])
route -nwill tell you the ip of your router/gateway – Sylvain Pineau Mar 09 '15 at 16:51subprocess.check_output()from python or use a dedicated lib (See http://stackoverflow.com/questions/2761829/python-get-default-gateway-for-a-local-interface-ip-address-in-linux) – Sylvain Pineau Mar 09 '15 at 16:57