Skip to content

Instantly share code, notes, and snippets.

@d1b
Created September 10, 2011 07:57
Show Gist options
  • Save d1b/1208091 to your computer and use it in GitHub Desktop.
Save d1b/1208091 to your computer and use it in GitHub Desktop.
shorewall-log-kmsg-parser
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