当前位置: 编程技术>python
python通过scapy获取局域网所有主机mac地址示例
来源: 互联网 发布时间:2014-10-04
本文导语: python通过scapy获取局域网所有主机mac地址 代码如下:#!/usr/bin/env python# -*- coding: utf-8 -*-from scapy.all import srp,Ether,ARP,confipscan='192.168.1.1/24'try: ans,unans = srp(Ether(dst="FF:FF:FF:FF:FF:FF")/ARP(pdst=ipscan),timeout=2,verbose=False)except Exception,e: ...
python通过scapy获取局域网所有主机mac地址
代码如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from scapy.all import srp,Ether,ARP,conf
ipscan='192.168.1.1/24'
try:
ans,unans = srp(Ether(dst="FF:FF:FF:FF:FF:FF")/ARP(pdst=ipscan),timeout=2,verbose=False)
except Exception,e:
print str(e)
else:
for snd,rcv in ans:
list_mac=rcv.sprintf("%Ether.src% - %ARP.psrc%")
print list_mac