fix get_location
This commit is contained in:
@ -4,8 +4,16 @@ from app.utils.http import RequestUtils
|
||||
|
||||
|
||||
class WebUtils:
|
||||
|
||||
@staticmethod
|
||||
def get_location(ip: str):
|
||||
"""
|
||||
查询IP所属地
|
||||
"""
|
||||
return WebUtils.get_location1(ip) or WebUtils.get_location2(ip)
|
||||
|
||||
@staticmethod
|
||||
def get_location1(ip: str):
|
||||
"""
|
||||
https://api.mir6.com/api/ip
|
||||
{
|
||||
@ -39,6 +47,31 @@ class WebUtils:
|
||||
print(str(err))
|
||||
return ""
|
||||
|
||||
@staticmethod
|
||||
def get_location2(ip: str):
|
||||
"""
|
||||
https://whois.pconline.com.cn/ipJson.jsp?json=true&ip=
|
||||
{
|
||||
"ip": "122.8.12.22",
|
||||
"pro": "上海市",
|
||||
"proCode": "310000",
|
||||
"city": "上海市",
|
||||
"cityCode": "310000",
|
||||
"region": "",
|
||||
"regionCode": "0",
|
||||
"addr": "上海市 铁通",
|
||||
"regionNames": "",
|
||||
"err": ""
|
||||
}
|
||||
"""
|
||||
try:
|
||||
r = RequestUtils().get_res(f"https://whois.pconline.com.cn/ipJson.jsp?json=true&ip={ip}")
|
||||
if r:
|
||||
return r.json().get("addr") or ''
|
||||
except Exception as err:
|
||||
print(str(err))
|
||||
return ""
|
||||
|
||||
@staticmethod
|
||||
def get_bing_wallpaper() -> Optional[str]:
|
||||
"""
|
||||
|
Reference in New Issue
Block a user