获取局域网Mac地址

首先安装scapy

scapy是啥我就不多做介绍了具体详见:http://www.secdev.org/projects/scapy/

安装:

wget http://www.secdev.org/projects/scapy/files/scapy-latest.tar.gz
tar -zxf scapy-latest.tar.gz
cd scapy-2.1.0/
python setup.py install

#!/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

执行结果:

获取局域网Mac地址

提示:WARNING: No route found for IPv6 destination :: (no default route?)

vim /usr/lib/python2.6/site-packages/scapy/all.py,注视掉下面 三行:

#if conf.ipv6_enabled:
#    from utils6 import *
#    from route6 import *

你可能感兴趣的:(python,Scapy)