Last active
October 27, 2016 01:58
-
-
Save D3f0/81a45b6cb6076e895f476b23d3aa32c3 to your computer and use it in GitHub Desktop.
parser linea iptables LOG
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
# Esqueleto para port knocker (Administración de Redes y Seguridad 2016) | |
# iptables -A INPUT -j LOG | |
# ejecutar script con sudo | |
# Probar en Ubntu, ya que CORE no tiene /var/log/syslog | |
import re | |
import subprocess | |
def converit_a_dict(linea): | |
tmp = {} | |
for fragmento in re.findall(r'(\w+\=[\w\d\.]+)', linea): | |
k, v = fragmento.split('=') | |
tmp[k] = v | |
ts = re.search(r'\[(?P<timestamp>\d+\.\d+)\]', linea).group('timestamp') | |
tmp['timestamp'] = float(ts) | |
return tmp | |
# converit_a_dict('[12345.15125] COSA=1245aabbx SRC=192.168.1.1 DST=10.0.0.1 1=a') | |
# para leer una linea cada vez que está disponible antes de analizar | |
# tail --follow, imprime por salida estandard cada vez que cambia el archivo | |
proceso = subrpocess.Popen("tail -f /var/log/syslog", shell=True, stdout=subprocess.PIPE) | |
while True: | |
linea = proceso.stdout.readline() | |
print converit_a_dict(linea) | |
# Hacer algo util con iptables | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Como eran los comando en nc para poder probarlo?