Created
June 30, 2016 19:20
-
-
Save haykuro/a5fee41571c4525928859345480ebe83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
logging.getLogger("scapy.runtime").setLevel(logging.ERROR) | |
from scapy.all import * | |
from json import dumps | |
from sys import argv | |
if len(argv) < 2: | |
print 'Usage:\n\t%s <your.pcap>' % (argv[0]) | |
exit(0) | |
packet_data = rdpcap(argv[1]) | |
formatted_objs = [] | |
for packet in packet_data: | |
packet_obj = {} | |
if Raw in packet: | |
packet_obj['load'] = packet[Raw].load | |
if IP in packet: | |
packet_obj['source_addr'] = packet[IP].src | |
packet_obj['dest_addr'] = packet[IP].dst | |
if TCP in packet: | |
packet_obj['source_port'] = packet[TCP].sport | |
packet_obj['dest_port'] = packet[TCP].dport | |
formatted_objs.append(packet_obj) | |
print dumps(formatted_objs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment