Last active
January 25, 2019 15:12
-
-
Save kanazux/68fbd8290cf926855e5dfa6af7775458 to your computer and use it in GitHub Desktop.
Return a dict from packet in pcap file
This file contains 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
#!/bin/env python | |
# -*- coding: utf-8 -*- | |
from datetime import datetime | |
from collections import defaultdict | |
from scapy.all import IP, Raw, rdpcap | |
class get_dump_data(object): | |
def __init__(self, dump_file): | |
self.dump = rdpcap(dump_file) | |
self.pkt_list = [] | |
def get_data(self): | |
for item in self.dump: | |
_new_dict = defaultdict(lambda: False) | |
_new_dict["time"] = datetime.utcfromtimestamp(item.time).strftime( | |
'%Y-%m-%d %H:%M:%S') | |
if IP in item: | |
_new_dict["id"] = item[IP].id | |
_new_dict["src"] = item[IP].src | |
_new_dict["dst"] = item[IP].dst | |
_new_dict["proto"] = item[IP].proto | |
if TCP in item: | |
_new_dict["sport"] = item[TCP].sport | |
_new_dict["dport"] = item[TCP].dport | |
if Raw in item: | |
_new_dict["raw"] = str(item[Raw].load) | |
self.pkt_list.append(_new_dict) | |
def run(self): | |
self.get_data() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment