from scapy.all import *
import requests
import re
wifi = 'wlp3s0' # 把网卡名字加上,网卡的名字在ubuntu命令行输入ifconfig可以找到
def MacToProduct(MAC):
header={
'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0'
}
url='https://mac.51240.com/{0}__mac/'.format(MAC)
response=requests.get(url,headers=header)
pattern=re.compile(' style="font-size:16px;">(.*?)</td>',re.S)
results=re.findall(pattern,response.text)
print(results)
while True:
p = Ether(dst='ff:ff:ff:ff:ff:ff') / ARP(pdst='192.168.1.1/24') # 如果有代码红线,应该是scrapy包或者ARP这个包没安装或者没导入
# ans表示收到的包的回复
ans, unans = srp(p, iface=wifi, timeout=4)
print("一共扫描到{0}台主机:" .format(len(ans)))
#for s in ans:
#print(s)
#ans.show()
# 将需要的IP地址和Mac地址存放在result列表中
result = []
for s, r in ans:
MAC=r[ARP].hwsrc
print(r[ARP].psrc)
#print(MAC)
MacToProduct(MAC)
time.sleep(5)
output:
***..***...*****............................................................................................................................................................................................................
Received 220 packets, got 11 answers, remaining 245 packets
一共扫描到11台主机:
192.168.1.3
['f4:2a:7d:7d:xx', 'TP-LINK TECHNOLOGIES CO.,LTD.(普联)']
192.168.1.1
['f8:8c:21:bc:xx:xx', 'TP-LINK TECHNOLOGIES CO.,LTD.(普联)']
192.168.1.2
['f4:2a:7d:a4:xxxx', 'TP-LINK TECHNOLOGIES CO.,LTD.(普联)']
192.168.1.10
['64:bc:58:8d:xx:xxx', 'Intel Corporate(英特尔)']
192.168.1.12
['c0:8a:cd:40:xx:xxxx', 'Guangzhou Shiyuan Electronic Technology Company Limited']
192.168.1.11
['44:59:e3:62:xxx:xxxx', 'HUAWEI TECHNOLOGIES CO.,LTD(华为)']
192.168.1.22
['18:cf:xxxx:ab', 'Liteon Technology Corporation']
192.168.1.18
['e0:b5:xxxx:c7:5e', 'Apple, Inc.(苹果公司)']
192.168.1.24
['3c:a0:xx:xx:a7', 'Liteon Technology Corporation']
192.168.1.32
['84:5c:f3:xxx:ef', 'Intel Corporate(英特尔)']
192.168.1.26
['20:47:da:17:xxxx', 'Xiaomi Communications Co Ltd(小米)']
Begin emission:
Finished sending 256 packets.
***.*****..**.*............
Received 27 packets, got 11 answers, remaining 245 packets