使用python检测ARP扫描

时间:2018-03-26 17:01:23

标签: python pcap pyshark

我想检测是否有人在网络上执行ARP扫描并显示源IP。意外的ARP请求数不足以检测ARP扫描。这是我的代码 -

element type

我想在数据包的 tell 部分中提取源IP,即IP。我做不到。有人可以告诉我如何在我的情况下显示源IP吗?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。这可以使用scapy而不是pyshark来完成!

from scapy.all import *


packets = sniff(offline=filename,filter='arp')
source='' 
source_mac=''
count=0

for pkt in packets:
    if pkt[ARP].op==1:
        count=count+1
        if count==5:
            source = pkt.sprintf("%ARP.psrc%")
            source_mac = pkt.sprintf("%ARP.hwsrc%")


if count>10:
    print "\nSomeone is scanning your network!"
    print "Source (IP): ",source
    print "Mac Address of Attacker: ",source_mac

else:
    print ("No Scan Identified!")

此外,我们可以使用scapy访问 is_at 告知字段:

operation = packet.sprintf("%ARP.op%")
if operation=="is_at":
   #do stuff