Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import requests | |
| # Function to get public IP address | |
| def get_ip_address(): | |
| try: | |
| # Request the IP from an external API (ipify) | |
| response = requests.get("https://api.ipify.org?format=json") | |
| ip = response.json().get("ip") | |
| return ip | |
| except requests.exceptions.RequestException as e: | |
| st.error(f"Error: {e}") | |
| return None | |
| # Streamlit app | |
| def main(): | |
| st.title("Public IP Address Finder") | |
| # Button to fetch the IP address | |
| if st.button("Get My IP Address"): | |
| ip_address = get_ip_address() | |
| if ip_address: | |
| st.success(f"Your Public IP Address is: {ip_address}") | |
| else: | |
| st.error("Failed to retrieve IP address") | |
| if __name__ == "__main__": | |
| main() | |