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 抓包驅動
2 https://mac.51240.com/ 元素是否更改
3 ans包含兩類數據包(ARP請求包和ARP返回信息),請求包是第一步構造的包,返回包是局域網內主機的迴應,如下圖所示。
參考文獻