I am able to read a packet from .pcap
file using pyshark
. Here is my code:
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
Now, I need to send this packet to some interface (e.g. eth0
). I tried the follwoing:
from socket import socket, AF_PACKET, SOCK_RAW
sock = socket(AF_PACKET, SOCK_RAW)
sock.bind(('eth0', 0))
sock.send(cap[0])
But I get the error:
sock.send(cap[0])
TypeError: a bytes-like object is required, not 'Packet'
Can anyone help?