Skip to content

Instantly share code, notes, and snippets.

@dhellmann
Created October 3, 2023 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhellmann/09c3f983763ab355758aee669eafb30a to your computer and use it in GitHub Desktop.
Save dhellmann/09c3f983763ab355758aee669eafb30a to your computer and use it in GitHub Desktop.
script to summarize source info in conntrack output
#!/usr/bin/env python3
import collections
import fileinput
import operator
import sys
sources = collections.defaultdict(int)
for line in fileinput.input(sys.argv[1:]):
parts = line.split()
for p in parts:
if p.startswith('src='):
sources[p] += 1
break
for src, count in reversed(sorted(sources.items(), key=operator.itemgetter(1))):
print(f'{count:6} {src}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment