我一直在嘗試創建一個類似于 netdiscover 的網絡掃描儀。我使用 Python 和 Scapy 模塊來做到這一點。我在虛擬盒子上的 Kali linux 上運行我的腳本,當我掃描由 Virtual Box 創建的 NAT 網絡時,它向我顯示已連接的設備,但是當我使用無線適配器掃描我的 wifi 網絡時,掃描儀無法找到任何設備,這很奇怪,因為 netdiscover 找到了大量的設備。但是,當我使用 Scapy 實現的 arping 功能時,設備也會顯示,但是當我運行我的代碼時,它不會檢測到任何設備。這是為什么?我使用了 Scapy 文檔建議的代碼,但它仍然沒有顯示任何設備。只有 Scapy arping 功能才能檢測到任何設備import scapy.all as scapyimport subprocess as subimport redef get_IP(): output=sub.check_output("route -n",shell=True) ips={} for row in output.split("\n")[2:]: found=re.findall("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}",row) device=re.findall("[a-z]{2,10}\d$",row) for ip in found: if ("0.0.0" not in ip and "255.255.255" not in ip): ips[device[0]]=ip for device,ip in ips.items(): print("Device: {}\tIP: {}".format(device,ip)) device = raw_input("Choose a device > ") return(ips[device][:-1]+"1/24")def scan(ip): #My code print("Scanning...") arp_request=scapy.ARP(pdst=ip) brodcast=scapy.Ether(dst="ff:ff:ff:ff:ff:ff") arp=brodcast/arp_request answered=scapy.srp(arp, timeout=1,verbose=False)[0] for element in answered: print("IP:{}".format(element[1].psrc)) print("MAC address: {}\n".format(element[1].hwsrc))def scan2(ip): #Code from scapy documentation and it's also not detecting any devices ans, unans = scapy.srp(scapy.Ether(dst="ff:ff:ff:ff:ff:ff")/scapy.ARP(pdst=ip),timeout=2) ans.summary(lambda (s,r): r.sprintf("%Ether.src% %ARP.psrc%") )def scan3(ip): #This works scapy.arping(ip)ip = get_IP()scan(ip)scan2(ip)scan3(ip)
2 回答

拉莫斯之舞
TA貢獻1820條經驗 獲得超10個贊
我只是通過停用與 NAT 網絡的連接來解決它,所以我使用了ifconfig eth0 down. 但是在某些情況下,這不是問題。如果您的路由器不允許網絡掃描,您需要更改您的 MAC 地址,這意味著您需要運行一系列這些命令
ifconfig wlan0 down
ifconfig wlan0 hw ether 00:22:44:66:88:33 # Ofcourse you can choose any MAC address you want
ifconfig wlan0 down
ifconfig wlan0 up
service network-manager restart
之后,網絡掃描儀將檢測當前在網絡中的設備

心有法竹
TA貢獻1866條經驗 獲得超5個贊
試試這種方式:
from scapy.all import scapy,ARP,Ether,srp,arping
或者這樣:
from scapy.layers.l2 import *
在這兩種情況下,請記住刪除“scapy.”,如下所示:
#Before
scapy.arping(ip)
#After
arping(ip)
添加回答
舉報
0/150
提交
取消