我已经搜索了一个标识符,我试图在我的服务器上找到任何连接设备的 mac 地址,但问题是输出返回空例如
a = os.popen("arp -a 192.168.6.150 | awk '{print $4}'").readlines()
a 为空
我正在处理强制门户页面以解开。我想从网络上设备的 ip 获取 mac 地址。此代码在 Apache 服务器上运行。
from mod_python import apache
from mod_python import util
我已经搜索了一个标识符,我试图在我的服务器上找到任何连接设备的 mac 地址,但问题是输出返回空例如
a = os.popen("arp -a 192.168.6.150 | awk '{print $4}'").readlines()
a 为空
我正在处理强制门户页面以解开。我想从网络上设备的 ip 获取 mac 地址。此代码在 Apache 服务器上运行。
from mod_python import apache
from mod_python import util
以下函数返回 mac 或None
如果 mac 未找到。
import commands
def getmac(iface):
mac = commands.getoutput("ifconfig " + iface + "| grep HWaddr | awk '{ print $5 }'")
if len(mac)==17:
return mac
getmac('eth0')
import re, uuid
print (' : '.join(re.findall('..', '%012x' % uuid.getnode())))
您也可以使用 python scapy模块
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")