亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 Scapy 實現 ARP ping?

如何使用 Scapy 實現 ARP ping?

三國紛爭 2022-06-02 15:25:01
我一直在嘗試創建一個類似于 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

之后,網絡掃描儀將檢測當前在網絡中的設備


查看完整回答
反對 回復 2022-06-02
?
心有法竹

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)


查看完整回答
反對 回復 2022-06-02
  • 2 回答
  • 0 關注
  • 165 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號