Skip to content

Instantly share code, notes, and snippets.

@subpath
Created April 1, 2019 17:21
Show Gist options
  • Select an option

  • Save subpath/2bf6fb0a2195061c9312d0522e3c3aa0 to your computer and use it in GitHub Desktop.

Select an option

Save subpath/2bf6fb0a2195061c9312d0522e3c3aa0 to your computer and use it in GitHub Desktop.
how to read pcap file in a slow way
from scapy.all import *
from tqdm import tqdm
import pandas as pd
raw = rdpcap(mypcap.pcap)
ip_data = []
tcp_data = []
for frame in tqdm(raw, desc='Converting'):
if 'options' in frame['IP'].fields: del frame['IP'].fields['options']
if 'flags' in frame['IP'].fields: del frame['IP'].fields['flags']
ip_data.append(pd.DataFrame(frame['IP'].fields, index=[0]))
tcp_data.append(pd.DataFrame(frame['TCP'].fields, index=[0]))
ip_data = pd.concat(ip_data, axis=0)
cols = [col + '_ip' for col in ip_data.columns]
ip_data.columns = cols
tcp_data = pd.concat(tcp_data, axis=0)
cols = [col + '_tcp' for col in tcp_data.columns]
tcp_data.columns = cols
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment