python脚本获取主机Mac地址

#!/usr/bin/python
import re
import subprocess
ARP = "arp"
IP = "192.168.128.27"
CMD = "%s %s" % (ARP,IP)
macPattern = re.compile(":")
def getMac():
p = subprocess.Popen(CMD,shell=True,stdout=subprocess.PIPE)
out = p.stdout.read()
results = out.split()
for chunk in results:
if re.search(macPattern,chunk):
return chunk
if __name__ == "__main__":
macAddr = getMac()
print macAddr
原文地址:https://www.cnblogs.com/Dev0ps/p/7778596.html