【发布时间】:2019-02-23 00:38:17
【问题描述】:
我可以使用pyshark 从.pcap 文件中读取数据包。这是我的代码:
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'
谁能帮忙?
【问题讨论】: