獲取內網中所有主機網卡的 mac 和 生產廠家

from scapy.all import srp, Ether, ARP
from time import *
import requests
from lxml import etree


def _otherScan():
    IpScan = '192.168.0.1/24'
    # 本機網卡名稱 ipconfig -all  描述. . . . . . . . . . . . . . . : Realtek PCIe GbE Family Controller
    wifi = 'Realtek PCIe GbE Family Controller'
    try:
        p = Ether(dst="FF:FF:FF:FF:FF:FF") / ARP(pdst=IpScan)
        #ans, unans = srp(p, timeout=2)
        ans, unans = srp(p, iface= wifi, timeout=2)
    except Exception as e:
        print(e)
    else:
        for send, rcv in ans:
            send.show()
            ListMACAddr = rcv.sprintf("%Ether.src%---%ARP.psrc%")
            #print(ListMACAddr)
            mac = rcv[ARP].hwsrc
            url = 'https://mac.51240.com/{0}__mac/'.format(mac)
            #print(url)
            response = requests.get(url)
            html = etree.HTML(response.text)
            mactext = html.xpath('//td[@style="font-size:16px;"]')
            for i in mactext:
                print(i.text)

    #sleep(10)
    #print(response.text)

_otherScan()

注意:

1 安裝 WinPcap 抓包驅動

https://mac.51240.com/ 元素是否更改

3 ans包含兩類數據包(ARP請求包和ARP返回信息),請求包是第一步構造的包,返回包是局域網內主機的迴應,如下圖所示。

參考文獻

http://pdcfighting.com/2020/04/17/%e4%bd%bf%e7%94%a8pyhton%e5%b8%a6%e4%bd%a0%e5%88%86%e6%9e%90%e9%85%92%e5%ba%97%e9%87%8c%e7%9a%84%e9%92%88%e5%ad%94%e6%91%84%e5%83%8f%e5%a4%b4/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章