import requests

ip_address = input("请输入要查询的 IP 地址:")
response = requests.get(f"http://ip-api.com/json/{ip_address}").json()

if response["status"] != "success":
    print("查询失败,请检查 IP 地址是否正确")
else:
    print(f"IP地址: {response['query']}")
    print(f"所在城市: {response['city']}")
    print(f"所在国家: {response['country']}")
    print(f"运营商: {response['isp']}")
这个 API 可能会通过限制访问次数来保护其服务,因此不建议进行大规模的查询。如果您需要频繁查询 IP 地址,请考虑使用其他服务或搭建自己的 IP 地址查询服务。