scapy相关

python 的 scapy 库可以方便的抓包与解析包

pip install scapy

抓包:

from scapy.all import *

dpkt  = sniff(filter='', iface='any',prn=function,count=n)

最简单的嗅探器:

cat mail_sniffer.py

from scapy.all import *

#数据包回调函数

def packet_callbak(packet)

    print(packet.show())

#开启嗅探器

sniff(prn=packet_callbak,iface='any',count=1)




pcap合适保存:

wrpcap("demo.pcap", dpkt)



cat mail_sniffer2.0.py

from scapy.all import *

#数据包回调函数

def packet_callbak(packet):

if packet[TCP].payload:

mail_packet=str(packet[TCP].payload)

if "user" in mail_packet.lower() or "pass" in mail_packet.lower()

你可能感兴趣的:(scapy相关)