mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-26 00:53:54 +08:00
get_ip_info接口优化
将失效的https://freeipapi.com/api/json替换为https://whois.pconline.com.cn/ipJson.jsp?json=true
This commit is contained in:
@@ -67,13 +67,11 @@ def is_private_ip(ip_addr):
|
|||||||
|
|
||||||
def get_ip_info(ip_addr):
|
def get_ip_info(ip_addr):
|
||||||
try:
|
try:
|
||||||
base_url = "https://freeipapi.com/api/json"
|
url = "https://whois.pconline.com.cn/ipJson.jsp?json=true"
|
||||||
url = base_url if is_private_ip(ip_addr) else f"{base_url}/{ip_addr}"
|
|
||||||
|
|
||||||
resp = requests.get(url).json()
|
resp = requests.get(url).json()
|
||||||
|
|
||||||
ip_info = {
|
ip_info = {
|
||||||
"city": resp.get("cityName")
|
"city": resp.get("city")
|
||||||
}
|
}
|
||||||
return ip_info
|
return ip_info
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user