当前位置 : 主页 > 编程语言 > python >

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

来源:互联网 收集:自由互联 发布时间:2022-09-02
用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) #

用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 回调函数



上一篇:centos7安装python3
下一篇:没有了
网友评论