Python gets an example of all host MAC addresses on the LAN through scapy

  • 2020-04-02 13:39:12
  • OfStack

Python gets all the host MAC addresses on the LAN through scapy


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


< img SRC = "border = 0 / / files.jb51.net/file_images/article/201405/20140504094313.jpg? 20144494345 ">


Related articles: