I am trying to write a python program using scapy to get various details of the packet such as src/dest IP/port #. As part of this I need to get the packet time of arrival and the time between packets in each direction, and the total number of packets and bytes in each direction.
It is very similar to Can reading sessions from a pcap file with Scapy be made more memory efficient
In the code below, pkttime is not working. How do I get the packet arrival time? Thanks for your help.
from scapy.all import *
pcap_file = "test.pcap"
a = rdpcap(pcap_file)
sessions = a.sessions()
for k, v in sessions.items():
tot_packets = len(v)
proto, source, dir, target = k.split()
srcip, srcport = source.split(":")
dstip, dstport = target.split(":")
if dir == '>':
direction="outbound"
else:
direction="inbound"
pkttime = v.time
print('%s,%s,%s,%s,%s,%s,%s,%s\n' % (srcip, dstip, proto, srcport,
dstport, tot_packets, direction, pkttime))