import scapy.all as scapy
import requests
import json
此代码与 API 一起用于获取有关供应商的信息
def vender_finding(mac_adr):
mac_url = 'http://macvendors.co/api/%s'
vender = (requests.get(mac_url % mac_adr))
response_dict = json.loads(json.dumps(vender.json()))
return response_dict['result']['company']
此代码返回连接到网络的所有设备。结果是这样的
def scan(ip):
arp_request = scapy.ARP(pdst=ip)
broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
arp_request_broadcast = broadcast/arp_request
这是给出错误的行
answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
clents_list = []
for element in answered_list[1:]:
company = vender_finding(element[1].hwsrc)
clent_dict = {"ip": element[1].psrc, "mac": element[1].hwsrc, "vender": company}
clents_list.append(clent_dict)
print(clents_list)
return clents_list
scan('192.168.1.0/24')
但现在它的返回错误是这样的。现在在这里开始出现一个新的错误。
answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
这是我得到的错误。
raise ValueError("Unknown network interface %r" % name)
ValueError: Unknown network interface None