Spaces:
Sleeping
Sleeping
File size: 1,452 Bytes
6e78b00 c6742c4 6e78b00 c6742c4 6e78b00 c6742c4 6e78b00 c6742c4 6e78b00 c6742c4 6e78b00 c6742c4 6e78b00 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import gradio as gr
import requests
import ipaddress
def ip_lookup(ip_address):
try:
# Validate and check if it's a private IP
ip_obj = ipaddress.ip_address(ip_address)
if ip_obj.is_private:
return "⚠️ This is a private/local IP address. Lookup not available."
response = requests.get(f"http://ip-api.com/json/{ip_address}")
data = response.json()
if data["status"] == "fail":
return f"❌ Error: {data.get('message', 'Invalid IP address')}"
result = f"""
**IP Address**: {data.get('query', 'N/A')}
**Country**: {data.get('country', 'N/A')}
**Region**: {data.get('regionName', 'N/A')}
**City**: {data.get('city', 'N/A')}
**ZIP**: {data.get('zip', 'N/A')}
**Latitude/Longitude**: {data.get('lat', 'N/A')}, {data.get('lon', 'N/A')}
**Timezone**: {data.get('timezone', 'N/A')}
**ISP**: {data.get('isp', 'N/A')}
**Organization**: {data.get('org', 'N/A')}
"""
return result.strip()
except ValueError:
return "❌ Invalid IP address format."
except Exception as e:
return f"❌ Error: {str(e)}"
iface = gr.Interface(
fn=ip_lookup,
inputs=gr.Textbox(label="Enter IP Address", placeholder="e.g. 8.8.8.8"),
outputs=gr.Markdown(label="IP Lookup Result"),
title="IP Lookup Tool",
description="Enter a public IP address to get geolocation, ISP, organization, and more."
)
if __name__ == "__main__":
iface.launch()
|