用户工具

站点工具


程序设计:python:获取公网ip
import requests
 
def get_public_ip():
    try:
        response = requests.get('https://httpbin.org/ip')
        response.raise_for_status()  # 检查是否请求成功
        ip = response.json()['origin']
        return ip
    except requests.RequestException as e:
        print(f"Error: {e}")
        return None
 
public_ip = get_public_ip()
if public_ip:
    print(f"Your public IP is: {public_ip}")
else:
    print("Unable to get your public IP.")
 
程序设计/python/获取公网ip.txt · 最后更改: 2024/05/10 01:56 由 lnote