我已经搜索了标识符,并尝试为我的服务器上的任何连接设备查找mac地址,但问题是输出返回空,例如
a = os.popen("arp -a 192.168.6.150 | awk '{print $4}'").readlines()
A为空
我正在为untangle做专属门户页面。我想从网络设备的ip地址中获取mac地址。此代码在Apache服务器上运行。
from mod_python import apache
from mod_python import util发布于 2013-08-26 23:23:08
如果没有找到mac,下面的函数将返回mac或None。
import commands
def getmac(iface):
mac = commands.getoutput("ifconfig " + iface + "| grep HWaddr | awk '{ print $5 }'")
if len(mac)==17:
return mac
getmac('eth0')发布于 2017-06-27 16:25:03
import re, uuid
print (' : '.join(re.findall('..', '%012x' % uuid.getnode())))发布于 2019-01-23 18:07:32
您也可以使用python 模块来实现同样的功能。
from scapy.all import *
def get_mac(ip_address):
responses,unanswered = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=ip_address),timeout=2,retry=10)
# return the MAC address from a response
for s,r in responses:
return r[Ether].src
return None
get_mac("192.168.31.14")https://stackoverflow.com/questions/18446513
复制相似问题