File size: 776 Bytes
f801f4f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()