我可以.pcap
使用pyshark
. 这是我的代码:
import pyshark
cap = pyshark.FileCapture(pcap_dir) # pcap_dir is the directory of my pcap file
print(cap[0]) # Print a packet
print(cap[0]['IP'].src) # Print some header value
现在,我需要将此数据包发送到某个接口(例如eth0
)。我尝试了以下方法:
from socket import socket, AF_PACKET, SOCK_RAW
sock = socket(AF_PACKET, SOCK_RAW)
sock.bind(('eth0', 0))
sock.send(cap[0])
但我得到了错误:
sock.send(cap[0])
TypeError: a bytes-like object is required, not 'Packet'
任何人都可以帮忙吗?