Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,47 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import socket
|
| 3 |
|
| 4 |
-
# Function to
|
| 5 |
-
def
|
| 6 |
try:
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
url = url[7:]
|
| 10 |
-
elif url.startswith('https://'):
|
| 11 |
-
url = url[8:]
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
ip_address = socket.gethostbyname(url)
|
| 18 |
-
return ip_address
|
| 19 |
except socket.gaierror:
|
| 20 |
-
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
# Streamlit app
|
| 24 |
def main():
|
| 25 |
-
st.title("
|
|
|
|
| 26 |
|
| 27 |
-
#
|
| 28 |
-
url = st.text_input("Enter
|
| 29 |
|
| 30 |
-
# Button to
|
| 31 |
-
if st.button("Get IP
|
| 32 |
if url:
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
if ip_address:
|
| 35 |
-
st.success(f"
|
|
|
|
|
|
|
|
|
|
| 36 |
else:
|
| 37 |
-
st.
|
| 38 |
|
| 39 |
if __name__ == "__main__":
|
| 40 |
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
import socket
|
| 4 |
|
| 5 |
+
# Function to get IP address and country name for a given URL
|
| 6 |
+
def get_ip_and_country(url):
|
| 7 |
try:
|
| 8 |
+
# Get the IP address of the website
|
| 9 |
+
ip_address = socket.gethostbyname(url)
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# Query the IP geolocation service (ipinfo.io)
|
| 12 |
+
response = requests.get(f"https://ipinfo.io/{ip_address}/json")
|
| 13 |
+
data = response.json()
|
| 14 |
+
|
| 15 |
+
# Extract country information
|
| 16 |
+
country = data.get("country", "Country not available")
|
| 17 |
|
| 18 |
+
return ip_address, country
|
|
|
|
|
|
|
| 19 |
except socket.gaierror:
|
| 20 |
+
return None, "Invalid URL or URL not found"
|
| 21 |
+
except requests.exceptions.RequestException as e:
|
| 22 |
+
return None, f"Error: {e}"
|
| 23 |
|
| 24 |
# Streamlit app
|
| 25 |
def main():
|
| 26 |
+
st.title("IP Address and Country Finder")
|
| 27 |
+
st.write("Enter the URL of the website below to find the IP address and country.")
|
| 28 |
|
| 29 |
+
# URL input by the user
|
| 30 |
+
url = st.text_input("Enter Website URL (e.g., www.example.com)")
|
| 31 |
|
| 32 |
+
# Button to submit and fetch details
|
| 33 |
+
if st.button("Get IP and Country"):
|
| 34 |
if url:
|
| 35 |
+
# Validate and fetch IP and country
|
| 36 |
+
ip_address, country = get_ip_and_country(url)
|
| 37 |
+
|
| 38 |
if ip_address:
|
| 39 |
+
st.success(f"IP Address: {ip_address}")
|
| 40 |
+
st.success(f"Country: {country}")
|
| 41 |
+
else:
|
| 42 |
+
st.error(country)
|
| 43 |
else:
|
| 44 |
+
st.error("Please enter a valid URL")
|
| 45 |
|
| 46 |
if __name__ == "__main__":
|
| 47 |
main()
|