Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import socket
|
| 3 |
+
from urllib.parse import urlparse
|
| 4 |
+
|
| 5 |
+
def domain_to_ip(website):
|
| 6 |
+
try:
|
| 7 |
+
# Ensure input is clean (remove http/https if present)
|
| 8 |
+
parsed_url = urlparse(website)
|
| 9 |
+
domain = parsed_url.netloc if parsed_url.netloc else parsed_url.path
|
| 10 |
+
|
| 11 |
+
if not domain:
|
| 12 |
+
return "❌ Invalid website input."
|
| 13 |
+
|
| 14 |
+
ip_address = socket.gethostbyname(domain)
|
| 15 |
+
return f"🌐 Domain: {domain}\n📍 IP Address: {ip_address}"
|
| 16 |
+
except socket.gaierror:
|
| 17 |
+
return "❌ Could not resolve domain. Please check the website name."
|
| 18 |
+
except Exception as e:
|
| 19 |
+
return f"❌ Error: {str(e)}"
|
| 20 |
+
|
| 21 |
+
iface = gr.Interface(
|
| 22 |
+
fn=domain_to_ip,
|
| 23 |
+
inputs=gr.Textbox(label="Enter Website URL or Domain", placeholder="e.g. google.com or https://example.com"),
|
| 24 |
+
outputs=gr.Markdown(label="IP Address"),
|
| 25 |
+
title="Website to IP Converter",
|
| 26 |
+
description="Enter a website name or URL (with or without http/https) to get its IP address."
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
iface.launch()
|