编程语言
首页 > 编程语言> > python3 利用scapy抓取网卡数据包并保存pcap

python3 利用scapy抓取网卡数据包并保存pcap

作者:互联网

用python scapy实现包的抓取,脚本如下

 

#coding=utf-8
from scapy.all import *
count = input("Input catch tcp num:")
now_time = datetime.now().strftime( "%Y%m%d%H%M%S" )
filename = "./pcap/email_dns_data_{0}.pcap".format(now_time)
#filter = 'tcp.port == 2222'
o_open_file= PcapWriter(filename, append=True)
def callback(packet):
    packet.show()
    o_open_file.write(packet)
  
dpkt_input = sniff(iface = "Realtek PCIe GBE Family Controller",count = int(count),  filter='tcp',prn = callback)

  sniff解释:

iface 网卡
filter 过滤条件,和wireshark 相同
count 抓包数量,0为永久抓包
prn 回调函数

标签:count,数据包,scapy,packet,网卡,tcp,now,pcap
来源: https://www.cnblogs.com/royfans/p/16366459.html