-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathping_parser.py
More file actions
23 lines (20 loc) · 768 Bytes
/
ping_parser.py
File metadata and controls
23 lines (20 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import pyshark
import sys
def extract_icmp_data(pcap_file):
cap = pyshark.FileCapture(pcap_file, display_filter='icmp')
for packet in cap:
try:
# Extracting ICMP data payload, which is in hex
icmp_data_hex = packet.icmp.data
# Convert hex to bytes then decode to ASCII
icmp_data_ascii = bytes.fromhex(icmp_data_hex).decode('ascii', errors='ignore')
print(icmp_data_ascii)
except AttributeError:
# In case the packet doesn't have ICMP data payload
continue
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python icmp_parser.py <path_to_pcap_file>")
sys.exit(1)
pcap_file = sys.argv[1]
extract_icmp_data(pcap_file)