v2.1 - Added Ninja Mode
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
# myip – IP & RIPE Lookup (extended)
|
# myip – IP & RIPE Lookup (extended)
|
||||||
|
|
||||||
UI moderna + IP reale + RIPE esteso (ASN, Provider, Prefix, Routing Status, Reverse DNS, GeoLocation, Abuse Contact).
|
UI moderna + IP reale + RIPE esteso (ASN, Provider, Prefix, Routing Status, Reverse DNS, GeoLocation, Abuse Contact).
|
||||||
|
v2.1 - Aggiunta funzionalità Ninja
|
||||||
|
https://fqdn/
|
||||||
|
→ comportamento normale, usa l’IP del client.
|
||||||
|
|
||||||
|
https://fqdn/?checkip=8.8.8.8
|
||||||
|
→ la pagina mostrerà i dati RIPE per 8.8.8.8, senza cambiare la UI.
|
||||||
|
|||||||
41
app.py
41
app.py
@@ -172,7 +172,25 @@ def get_client_ip():
|
|||||||
|
|
||||||
# 3) Fallback: remote_addr così com'è
|
# 3) Fallback: remote_addr così com'è
|
||||||
return request.remote_addr or "Sconosciuto"
|
return request.remote_addr or "Sconosciuto"
|
||||||
|
def get_effective_ip():
|
||||||
|
"""
|
||||||
|
Restituisce (ip, overridden)
|
||||||
|
- ip: indirizzo IP da usare per la lookup
|
||||||
|
- overridden: True se l'IP è stato forzato via ?checkip=
|
||||||
|
"""
|
||||||
|
override = request.args.get("checkip")
|
||||||
|
if override:
|
||||||
|
override = override.strip()
|
||||||
|
try:
|
||||||
|
# valida che sia un IP v4/v6
|
||||||
|
ipaddress.ip_address(override)
|
||||||
|
return override, True
|
||||||
|
except ValueError:
|
||||||
|
# se non è valido, ignora e usa il flusso normale
|
||||||
|
pass
|
||||||
|
|
||||||
|
# default: uso l'IP reale del client
|
||||||
|
return get_client_ip(), False
|
||||||
|
|
||||||
def fetch_ripe_info(ip: str):
|
def fetch_ripe_info(ip: str):
|
||||||
"""Recupera informazioni RIPEstat estese per l'IP, compatibili col template."""
|
"""Recupera informazioni RIPEstat estese per l'IP, compatibili col template."""
|
||||||
@@ -354,34 +372,15 @@ def fetch_ripe_info(ip: str):
|
|||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
ip = get_client_ip()
|
ip, overridden = get_effective_ip()
|
||||||
ripe_info = fetch_ripe_info(ip) if ip != "Sconosciuto" else None
|
ripe_info = fetch_ripe_info(ip) if ip != "Sconosciuto" else None
|
||||||
return render_template_string(
|
return render_template_string(
|
||||||
HTML_TEMPLATE,
|
HTML_TEMPLATE,
|
||||||
ip=ip,
|
ip=ip,
|
||||||
ripe=ripe_info,
|
ripe=ripe_info,
|
||||||
show_logo=True,
|
show_logo=True,
|
||||||
|
override=overridden,
|
||||||
)
|
)
|
||||||
@app.route("/debug")
|
|
||||||
def debug():
|
|
||||||
from flask import jsonify
|
|
||||||
return jsonify(
|
|
||||||
remote_addr=request.remote_addr,
|
|
||||||
x_forwarded_for=request.headers.get("X-Forwarded-For"),
|
|
||||||
x_real_ip=request.headers.get("X-Real-IP"),
|
|
||||||
all_headers=dict(request.headers),
|
|
||||||
)
|
|
||||||
|
|
||||||
@app.route("/ripe-debug")
|
|
||||||
def ripe_debug():
|
|
||||||
from flask import jsonify
|
|
||||||
ip = get_client_ip()
|
|
||||||
ripe_info = fetch_ripe_info(ip) if ip != "Sconosciuto" else None
|
|
||||||
return jsonify({
|
|
||||||
"ip": ip,
|
|
||||||
"ripe": ripe_info,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host="0.0.0.0", port=8000)
|
app.run(host="0.0.0.0", port=8000)
|
||||||
|
|||||||
Reference in New Issue
Block a user