Created
September 10, 2011 07:57
-
-
Save d1b/1208091 to your computer and use it in GitHub Desktop.
shorewall-log-kmsg-parser
This file contains hidden or 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
import sys | |
import socket | |
def return_red(string): | |
return "\033[1;31m" + string + "\033[m" | |
console = open("/dev/console", "w") | |
while True: | |
f = open("/proc/kmsg", 'r') | |
x = f.read(250) | |
output = "" | |
try: | |
remote_host_addr = x[x.find("SRC") + 4 :].split(" " )[0] | |
protocol = x[x.find("PROTO=") + 6:].split(" ")[0] | |
dest_port = x[x.find("DPT=") + 4:].split(" ")[0] | |
try: | |
remote_host_addr = socket.gethostbyaddr(remote_host_addr)[0] | |
except Exception, e: | |
output += str(repr(e)) | |
output += str(remote_host_addr) + " " + str(dest_port) + " " + str(protocol) | |
except Exception, e: | |
output += str(repr(e)) | |
if output != "\n": | |
output = return_red(output) | |
console.write(output) | |
print output | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment