Initial commit
This commit is contained in:
commit
a55db863b0
2 changed files with 26 additions and 0 deletions
8
Dockerfile
Normal file
8
Dockerfile
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
FROM python:3-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY ipserv.py /app
|
||||||
|
EXPOSE 8000
|
||||||
|
RUN pip install flask requests gunicorn
|
||||||
|
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0", "ipserv:app"]
|
||||||
|
|
18
ipserv.py
Normal file
18
ipserv.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import requests
|
||||||
|
from flask import Flask, request, make_response
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/")
|
||||||
|
def ip():
|
||||||
|
if "X-Real-IP" in request.headers:
|
||||||
|
ip = request.headers["X-Real-IP"]
|
||||||
|
else:
|
||||||
|
ip = request.remote_addr
|
||||||
|
response = requests.get("https://ip.shronk.net/lookup?ip=" + ip)
|
||||||
|
data = response.json()
|
||||||
|
data.pop("legalese")
|
||||||
|
data.pop("source")
|
||||||
|
data.pop("brexitRequired")
|
||||||
|
return data, response.status_code
|
Reference in a new issue