Created
June 9, 2012 15:06
-
-
Save jvehent/2901349 to your computer and use it in GitHub Desktop.
conntrack_parse_webforms.py
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
#!/usr/bin/env python | |
from collections import defaultdict | |
import sys | |
import datetime | |
counters = defaultdict(int) | |
entries = 0 | |
show_progress = 0 | |
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