Skip to content

Instantly share code, notes, and snippets.

@jjsantanna
Last active March 3, 2019 23:32
Show Gist options
  • Save jjsantanna/8ea706453ef843c8494d2a184e12e858 to your computer and use it in GitHub Desktop.
Save jjsantanna/8ea706453ef843c8494d2a184e12e858 to your computer and use it in GitHub Desktop.
getting all the last lines of multi-vector attacks logs (output from ddos_dissector) and outputting a .csv
#!/bin/bash
rm all_summaries.csv; ls |grep .log |while read file; do echo $file; tail -1 $file >> all_summaries.csv; done
@jjsantanna
Copy link
Author

jjsantanna commented Mar 3, 2019

import pandas as pd
import numpy as np

df = pd.read_csv("all_summaries.csv", sep=";")
df.columns = ['raw_filename','multivector_key', 'singlevector_keys', 'filters', '#_src_ips']
df.replace(np.nan, "[]", regex=True)

df['singlevector_keys'] = df['singlevector_keys'].apply(lambda x: str(x).strip('[]').split(', '))
df['filters'] = df['filters'].apply(lambda x: str(x).strip('[]').split(', '))
df['#_src_ips'] = df['#_src_ips'].apply(lambda x: str(x).strip('[]').split(', '))

singlevector_keys = df.apply(lambda x: pd.Series(x['singlevector_keys']),axis=1).stack().reset_index(level=1, drop=True)
singlevector_keys.name = 'singlevector_keys'

filters = df.apply(lambda x: pd.Series(x['filters']),axis=1).stack().reset_index(level=1, drop=True)
filters.name = 'filters'

src_ips = df.apply(lambda x: pd.Series(x['#_src_ips']),axis=1).stack().reset_index(level=1, drop=True)
src_ips.name = '#_src_ips'

df_temp = pd.DataFrame({'singlevector_key':singlevector_keys,
'filters':filters,
'#_src_ips':src_ips})

df_extended = df.drop(['singlevector_keys','filters','#_src_ips'], axis=1).join(df_temp)

df_extended.to_csv('summary.csv')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment