Read on packet capturing using pyshark


$python3  read_pcap.py > pcap-result.txt

$cat read_pcap.py 
#!/usr/bin/env python3

import pyshark

#cap = pyshark.FileCapture('http.cap', display_filter="dns")
#for pkt in cap:
#	print(pkt)
	
cap = pyshark.FileCapture('http.cap', keep_packets=False)

def print_info_layer(packet):
	print("[Protocol:] "+packet.highest_layer+" [Source IP:] "+packet.ip.src+" [Destination IP:]"+packet.ip.dst)
cap.apply_on_packets(print_info_layer)



$cat pcap-result.txt 
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] HTTP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] DNS [Source IP:] 145.254.160.237 [Destination IP:]145.253.2.203
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] DNS [Source IP:] 145.253.2.203 [Destination IP:]145.254.160.237
[Protocol:] HTTP [Source IP:] 145.254.160.237 [Destination IP:]216.239.59.99
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 216.239.59.99 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 216.239.59.99 [Destination IP:]145.254.160.237
[Protocol:] DATA-TEXT-LINES [Source IP:] 216.239.59.99 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]216.239.59.99
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 216.239.59.99 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]216.239.59.99
[Protocol:] XML [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
$
$python3  read_pcap.py > pcap-result.txt
$cat  pcap-result.txt
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] HTTP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] DNS [Source IP:] 145.254.160.237 [Destination IP:]145.253.2.203
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] DNS [Source IP:] 145.253.2.203 [Destination IP:]145.254.160.237
[Protocol:] HTTP [Source IP:] 145.254.160.237 [Destination IP:]216.239.59.99
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 216.239.59.99 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 216.239.59.99 [Destination IP:]145.254.160.237
[Protocol:] DATA-TEXT-LINES [Source IP:] 216.239.59.99 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]216.239.59.99
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 216.239.59.99 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]216.239.59.99
[Protocol:] XML [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223
[Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237
$  

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: