-
Notifications
You must be signed in to change notification settings - Fork 0
/
net.py
63 lines (50 loc) · 1.91 KB
/
net.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from fastapi import APIRouter, Request
from mysql_app.schemas import StandardResponse
china_router = APIRouter(tags=["Network"])
global_router = APIRouter(tags=["Network"])
fujian_router = APIRouter(tags=["Network"])
@china_router.get("/ip", response_model=StandardResponse)
def get_client_ip_cn(request: Request) -> StandardResponse:
"""
Get the client's IP address and division. In this endpoint, the division is always "China".
:param request: Request object from FastAPI, used to identify the client's IP address
:return: Standard response with the client's IP address and division
"""
return StandardResponse(
retcode=0,
message="success",
data={
"ip": request.client.host,
"division": "China"
}
)
@fujian_router.get("/ip", response_model=StandardResponse)
def get_client_ip_cn(request: Request) -> StandardResponse:
"""
Get the client's IP address and division. In this endpoint, the division is always "China".
:param request: Request object from FastAPI, used to identify the client's IP address
:return: Standard response with the client's IP address and division
"""
return StandardResponse(
retcode=0,
message="success",
data={
"ip": request.client.host,
"division": "Fujian - China"
}
)
@global_router.get("/ip", response_model=StandardResponse)
def get_client_ip_global(request: Request) -> StandardResponse:
"""
Get the client's IP address and division. In this endpoint, the division is always "Oversea".
:param request: Request object from FastAPI, used to identify the client's IP address
:return: Standard response with the client's IP address and division
"""
return StandardResponse(
retcode=0,
message="success",
data={
"ip": request.client.host,
"division": "Oversea"
}
)