Second Commit
This commit is contained in:
7
Dockerfile
Normal file
7
Dockerfile
Normal file
@@ -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"]
|
||||||
53
app.py
Normal file
53
app.py
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
from flask import Flask, request, render_template_string
|
||||||
|
import requests
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
HTML_TEMPLATE = """<!doctype html>
|
||||||
|
<html lang="it">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Il tuo IP pubblico</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2>Il tuo IP pubblico è: {{ ip }}</h2>
|
||||||
|
{% if ripe %}
|
||||||
|
<h3>Informazioni RIPE</h3>
|
||||||
|
<p>Provider: {{ ripe.holder }}</p>
|
||||||
|
<p>Prefisso: {{ ripe.prefix }}</p>
|
||||||
|
<p>ASN: {{ ripe.asns|join(', ') }}</p>
|
||||||
|
{% endif %}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"""
|
||||||
|
|
||||||
|
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)
|
||||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
Flask==3.0.3
|
||||||
|
requests==2.32.3
|
||||||
0
static/logo.png
Normal file
0
static/logo.png
Normal file
Reference in New Issue
Block a user