import http.server
import socket
import sys


def get_local_ip():
    with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
        s.connect(("8.8.8.8", 80))
        return s.getsockname()[0]


port = int(sys.argv[1]) if len(sys.argv) > 1 else 8000
ip = get_local_ip()

handler = http.server.SimpleHTTPRequestHandler
server = http.server.HTTPServer(("0.0.0.0", port), handler)

print(f"Serving on:")
print(f"  http://localhost:{port}")
print(f"  http://{ip}:{port}")
print("Press Ctrl+C to stop.")
server.serve_forever()
