diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dfcbf85 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.12-slim +WORKDIR /app +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt +COPY . . +EXPOSE 8000 +CMD ["python","app.py"] diff --git a/app.py b/app.py new file mode 100644 index 0000000..f6c8bc2 --- /dev/null +++ b/app.py @@ -0,0 +1,53 @@ +from flask import Flask, request, render_template_string +import requests + +app = Flask(__name__) + +HTML_TEMPLATE = """ + +
+ +Provider: {{ ripe.holder }}
+Prefisso: {{ ripe.prefix }}
+ASN: {{ ripe.asns|join(', ') }}
+ {% endif %} + + +""" + +def get_client_ip(): + xff = request.headers.get("X-Forwarded-For", "") + if xff: + return xff.split(",")[0].strip() + return request.remote_addr or "Sconosciuto" + +def fetch_ripe_info(ip: str): + try: + ni = requests.get("https://stat.ripe.net/data/network-info/data.json", + params={"resource": ip}, timeout=2).json().get("data", {}) + prefix = ni.get("prefix") + asns = ni.get("asns") or [] + holder=None + if asns: + ao = requests.get("https://stat.ripe.net/data/as-overview/data.json", + params={"resource": asns[0]}, timeout=2).json().get("data", {}) + holder = ao.get("holder") + return {"prefix": prefix, "asns":[f"AS{a}" for a in asns], "holder": holder} + except: + return None + +@app.route("/") +def index(): + ip = get_client_ip() + ripe = fetch_ripe_info(ip) if ip!="Sconosciuto" else None + return render_template_string(HTML_TEMPLATE, ip=ip, ripe=ripe) + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=8000) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..76d9083 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask==3.0.3 +requests==2.32.3 diff --git a/static/logo.png b/static/logo.png new file mode 100644 index 0000000..e69de29