Display information about the host
This commit is contained in:
parent
85036cfa76
commit
ed16a494f2
25
main.py
25
main.py
|
@ -1,9 +1,20 @@
|
||||||
|
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):
|
||||||
|
interfaces = {}
|
||||||
|
for interface in netifaces.interfaces():
|
||||||
|
interfaces[interface] = []
|
||||||
|
for link in netifaces.ifaddresses(interface).values():
|
||||||
|
for group in link:
|
||||||
|
interfaces[interface].append(group['addr'])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"method": request.method,
|
"method": request.method,
|
||||||
"url": {
|
"url": {
|
||||||
|
@ -18,4 +29,18 @@ 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(),
|
||||||
|
"python": platform.python_version(),
|
||||||
|
|
||||||
|
"os": {
|
||||||
|
"system": platform.system(),
|
||||||
|
"release": platform.release(),
|
||||||
|
"version": platform.version(),
|
||||||
|
"distro": platform.freedesktop_os_release(),
|
||||||
|
},
|
||||||
|
|
||||||
|
"ip-addresses": interfaces,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ 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
|
||||||
|
|
Loading…
Reference in New Issue