Skip to content

Instantly share code, notes, and snippets.

@jvehent
Created June 9, 2012 15:06
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 jvehent/2901349 to your computer and use it in GitHub Desktop.
Save jvehent/2901349 to your computer and use it in GitHub Desktop.
conntrack_parse_webforms.py
#!/usr/bin/env python
from collections import defaultdict
import sys
import datetime
counters = defaultdict(int)
entries = 0
show_progress = 0
print
conntrack_file = open("/proc/net/ip_conntrack")
for line in conntrack_file:
if show_progress:
entries += 1
if (entries % 997 == 0):
print entries
if "10.128.0.146" in line:
if "TIME_WAIT" in line:
counters["0-public-time_wait"] += 1
elif "ESTABLISHED" in line:
if "UNREPLIED" in line:
counters["1-public-established-unreplied"] += 1
elif "ASSURED" in line:
counters["2-public-established-assured"] += 1
else:
counters["3-public-established-unknown"] += 1
elif "10.1.1.146" in line:
if "TIME_WAIT" in line:
counters["4-lan-time_wait"] += 1
elif "ESTABLISHED" in line:
counters["5-lan-established"] += 1
elif "127.0.0.1" in line:
if "TIME_WAIT" in line:
counters["6-lo-time_wait"] += 1
elif "ESTABLISHED" in line:
counters["7-lo-established"] += 1
conntrack_file.close
print datetime.datetime.now()
for counter in sorted(counters):
print counter,": ",counters[counter]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment