You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
auto/utils/utils_get_public_ip.py

15 lines
437 B

# -*- coding: utf-8 -*-
import httpx
def get_public_ip():
try:
# 使用 httpx 发起请求
response = httpx.get("https://httpbin.org/ip", timeout=10)
response.raise_for_status() # 检查请求是否成功
ip_data = response.json()
return ip_data["origin"]
except httpx.RequestError as e:
print(f"An error occurred while obtaining the public IP address.:{e}")
exit(1)