Compare commits

..

4 Commits

Author SHA1 Message Date
Xeryus Stokkel
df1c24daa6
Header to toggle full response 2022-02-03 15:52:33 +01:00
Xeryus Stokkel
273e341789
Python 3.9 doesn't support getting the distro 2022-02-02 13:31:59 +01:00
Xeryus Stokkel
ed16a494f2
Display information about the host 2022-02-02 13:27:46 +01:00
Xeryus Stokkel
85036cfa76
Add gunicorn to requirements 2022-02-02 12:42:55 +01:00
2 changed files with 34 additions and 2 deletions

34
main.py
View File

@ -1,10 +1,14 @@
import platform
import socket
from fastapi import FastAPI, Header, Request from fastapi import FastAPI, Header, Request
import netifaces
app = FastAPI() app = FastAPI()
@app.get("/") @app.get("/")
def root(request: Request): def root(request: Request, x_full_response: bool = Header(False)):
return { response = {
"method": request.method, "method": request.method,
"url": { "url": {
"url": request.url._url, "url": request.url._url,
@ -18,4 +22,30 @@ def root(request: Request):
"ip-address": request.client.host, "ip-address": request.client.host,
"port": request.client.port, "port": request.client.port,
}, },
"host": {
"hostname": platform.node(),
"fqdn": socket.getfqdn(),
}
} }
if not x_full_response:
return response
interfaces = {}
for interface in netifaces.interfaces():
interfaces[interface] = []
for link in netifaces.ifaddresses(interface).values():
for group in link:
interfaces[interface].append(group['addr'])
response["host"].update({
"python": platform.python_version(),
"os": {
"system": platform.system(),
"release": platform.release(),
"version": platform.version(),
},
"ip-addresses": interfaces,
})
return response

View File

@ -2,9 +2,11 @@ anyio==3.5.0
asgiref==3.5.0 asgiref==3.5.0
click==8.0.3 click==8.0.3
fastapi==0.73.0 fastapi==0.73.0
gunicorn==20.1.0
h11==0.13.0 h11==0.13.0
httptools==0.3.0 httptools==0.3.0
idna==3.3 idna==3.3
netifaces==0.11.0
pydantic==1.9.0 pydantic==1.9.0
python-dotenv==0.19.2 python-dotenv==0.19.2
PyYAML==6.0 PyYAML==6.0