Desk-Back2 / test_network.py
Fred808's picture
Upload 77 files
5111c4b verified
import socket
import ssl
import sys
import os
from urllib.parse import urlparse
def test_network_connection(host, port):
try:
# Create a socket and set a timeout
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(10)
# Wrap the socket with SSL
context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
wrapped_socket = context.wrap_socket(sock)
# Try to connect
result = wrapped_socket.connect_ex((host, port))
if result == 0:
print(f"Successfully connected to {host}:{port}")
return True
else:
print(f"Failed to connect to {host}:{port}")
print(f"Error code: {result}")
return False
except Exception as e:
print(f"Error: {str(e)}")
return False
finally:
try:
wrapped_socket.close()
except:
pass
if __name__ == "__main__":
host = "juycnkjuzylnbruwaqmp.supabase.co"
port = 5432
print(f"Testing connection to {host}:{port}...")
print(f"Python version: {sys.version}")
print(f"Platform: {sys.platform}")
success = test_network_connection(host, port)
sys.exit(0 if success else 1)