Reputation: 119
Hi i am trying to get a python script to get a mac address from a arp -n command and i am struggling to get just the mac address.
current code:
for ipaddr in uip:
pid = Popen(["arp", "-n", ipaddr], stdout=PIPE)
s = pid.communicate()[0]
mac = re.search(r"(([a-f\d]{1,2}\:){5}[a-f\d]{1,2})", s)
print mac
uip is decleared at the begining of the script
current code out put
<_sre.SRE_Match object at 0x7f18f0ea9690>
<_sre.SRE_Match object at 0x7f18f0ea9718>
<_sre.SRE_Match object at 0x7f18f0ea9690>
<_sre.SRE_Match object at 0x7f18f0ea9718>
None
<_sre.SRE_Match object at 0x7f18f0ea9718>
<_sre.SRE_Match object at 0x7f18f0ea9690>
<_sre.SRE_Match object at 0x7f18f0ea9718>
<_sre.SRE_Match object at 0x7f18f0ea9690>
<_sre.SRE_Match object at 0x7f18f0ea9718>
Upvotes: 0
Views: 825
Reputation: 4155
You want the captured results (that is, those captured by the parentheses). Those can be accesed by mac.group
or mac.groups
methods.
Instead of print mac
you can use print mac.group(0) if mac else "No result"
.
Upvotes: 1