I\'m looking for a way (with python) to obtain the layer II
address from a device on my local network. Layer III
addresses are known.
The
General update for Python 3.7. Remark: the option -n
for arp
does not provide the arp list on windows systems as provided with certain answers for linux based systems. Use the option -a
as stated in the answer here.
from subprocess import Popen, PIPE
pid = Popen(['arp', '-a', ip], stdout=PIPE, stderr=PIPE)
IP, MAC, var = ((pid.communicate()[0].decode('utf-8').split('Type\r\n'))[1]).split(' ')
IP = IP.strip(' ')
MAC = MAC.strip(' ')
if ip == IP:
print ('Remote Host : %s\n MAC : %s' % (IP, MAC))