程序设计:python:获取公网ip
这是本文档旧的修订版!
<code python> 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.")
<code>
程序设计/python/获取公网ip.1715306133.txt.gz · 最后更改: 2024/05/10 01:55 由 lnote