scapy或者pysharkmitmproxy

from scapy.all import sniff

# 定义一个回调函数来处理每个抓到的包
def handle_packet(packet):
    print(packet.summary())

# 使用sniff函数开始捕获包,指定回调函数
sniff(prn=handle_packet, count=10)  # count=10表示只抓取10个包