Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python scapy get mac of remote device

>>> from subprocess import Popen, PIPE
>>> import re
>>> IP = "1.2.3.4"

>>> # do_ping(IP)
>>> # The time between ping and arp check must be small, as ARP may not cache long

>>> pid = Popen(["arp", "-n", IP], stdout=PIPE)
>>> s = pid.communicate()[0]
>>> mac = re.search(r"(([a-fd]{1,2}:){5}[a-fd]{1,2})", s).groups()[0]
>>> mac
"fe:fd:61:6b:8a:0f"
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #scapy #mac #remote #device
ADD COMMENT
Topic
Name
7+2 =