iptime: lookup the external IP address if this comes from inside the network.

master
Michael Hope 4 years ago
parent ff24f10caa
commit 03fa7d15f7

@ -6,6 +6,7 @@ from geoip import geolite2
import astral
import dateutil.tz
import flask
import requests
app = flask.Flask(__name__)
@ -14,11 +15,14 @@ def to_sec(dt):
return dt.hour * 60 * 60 + dt.minute * 60 + dt.second
@app.route('/iptime')
def iptime():
@app.route('/now')
def now():
ip = flask.request.args.get('ip')
if not ip:
ip = flask.request.remote_addr
if ip.startswith('192.168.') or ip.startswith('10.'):
r = requests.get('https://api.ipify.org?format=json')
ip = r.json().get('ip')
loc = geolite2.lookup(ip)
if loc is None:
flask.abort(

Loading…
Cancel
Save