File size: 1,149 Bytes
80feb1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import socket

def get_ip_address():
    """Get the local IP address of the machine."""
    print("Starting IP address detection...")
    try:
        # Create a socket connection to an external server
        print("Creating socket connection...")
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        # Doesn't need to be reachable
        print("Connecting to Google DNS (8.8.8.8)...")
        s.connect(("8.8.8.8", 80))
        print("Getting local socket name...")
        ip_address = s.getsockname()[0]
        s.close()
        print(f"Successfully detected IP: {ip_address}")
        return ip_address
    except Exception as e:
        print(f"Error getting IP address: {e}")
        return "127.0.0.1"  # Return localhost if there's an error

if __name__ == "__main__":
    print("\nStarting Tabble IP detection...")
    ip = get_ip_address()
    print("\nYour IP Address:", ip)
    print(f"\nYou can access the Tabble app at: http://{ip}:8000\n")
    print("Share this URL with other devices on your network to access the application.")
    print("Note: Make sure your firewall allows incoming connections on port 8000.")