From 5e7d446f792a5fba71606a71f6398e249446b1c7 Mon Sep 17 00:00:00 2001 From: clyhtsuriva Date: Thu, 21 May 2020 09:18:58 +0200 Subject: Beaucoup de changements --- www/html/ip_source.py | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 www/html/ip_source.py (limited to 'www/html/ip_source.py') diff --git a/www/html/ip_source.py b/www/html/ip_source.py new file mode 100755 index 0000000..861ea9a --- /dev/null +++ b/www/html/ip_source.py @@ -0,0 +1,77 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +import mod_python +from fonctions import baseHTML, connexionBD, lien +import socket + +def index(req): + req.content_type="text/html" + +#partie socket + +#check si ip est bien la + try: + ip=req.form["ip"] + except KeyError: + mod_python.util.redirect(req, "index.py") + +#check si ip a le bon format + try: + socket.inet_aton(ip) + except socket.error: + mod_python.util.redirect(req, "index.py") + + content=str() + +#reverse dns + try: + rdns=socket.gethostbyaddr(ip)[0] + except socket.herror: + rdns="Non connu" + +#partie socket + +#sql part + conn=connexionBD() + cur=conn.cursor() + + sql="SELECT * FROM paquet WHERE ip_source=%s ORDER BY heure DESC" + sql_count="SELECT COUNT(*) FROM paquet WHERE ip_source=%s" + + cur.execute(sql, (ip, )) + conn.commit() + data=cur.fetchall() + + cur.execute(sql_count, (ip, )) + conn.commit() + count=cur.fetchone() + + conn.close() +#sql part + +#takes every lines from the select + for i in data : + content+=("""""" + +"""""" + str(i[1]) + """""" + +"""""" + str(i[2]) + """""" + +"""""" + lien('ip_source.py?ip=' + str(i[3]), str(i[3])) + """""" + +"""""" + lien('ip_destination.py?ip=' + str(i[4]), str(i[4])) + """""" + +"""""" + lien('port_source.py?port=' + str(i[5]), str(i[5])) + """""" + +"""""" + lien('port_destination.py?port=' + str(i[6]), str(i[6])) + """""" + +"""""") + +#write the html page + req.write(baseHTML("ATS - " + ip,""" +

IP source : """ + ip + """

+

Nombre de paquets venant de """+ ip + """ : """+ str(count[0])+ """

+

Reverse DNS : """+rdns+"""

+

+ + +""" ++ content + +""" +
HeureProtocoleIP SourceIP DestinationPort SourcePort Destination
+
+""")) -- cgit v1.2.3