Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
def ip_lookup(ip_address):
|
| 5 |
+
try:
|
| 6 |
+
response = requests.get(f"http://ip-api.com/json/{ip_address}")
|
| 7 |
+
data = response.json()
|
| 8 |
+
|
| 9 |
+
if data["status"] == "fail":
|
| 10 |
+
return f"Error: {data.get('message', 'Invalid IP address')}"
|
| 11 |
+
|
| 12 |
+
result = f"""
|
| 13 |
+
**IP Address**: {data.get('query', 'N/A')}
|
| 14 |
+
**Country**: {data.get('country', 'N/A')}
|
| 15 |
+
**Region**: {data.get('regionName', 'N/A')}
|
| 16 |
+
**City**: {data.get('city', 'N/A')}
|
| 17 |
+
**ZIP**: {data.get('zip', 'N/A')}
|
| 18 |
+
**Latitude/Longitude**: {data.get('lat', 'N/A')}, {data.get('lon', 'N/A')}
|
| 19 |
+
**Timezone**: {data.get('timezone', 'N/A')}
|
| 20 |
+
**ISP**: {data.get('isp', 'N/A')}
|
| 21 |
+
**Organization**: {data.get('org', 'N/A')}
|
| 22 |
+
"""
|
| 23 |
+
return result.strip()
|
| 24 |
+
except Exception as e:
|
| 25 |
+
return f"Error: {str(e)}"
|
| 26 |
+
|
| 27 |
+
iface = gr.Interface(
|
| 28 |
+
fn=ip_lookup,
|
| 29 |
+
inputs=gr.Textbox(label="Enter IP Address", placeholder="e.g. 8.8.8.8"),
|
| 30 |
+
outputs=gr.Markdown(label="IP Lookup Result"),
|
| 31 |
+
title="IP Lookup Tool",
|
| 32 |
+
description="Enter an IP address to get geolocation, ISP, organization, and more."
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
if __name__ == "__main__":
|
| 36 |
+
iface.launch()
|