File size: 1,407 Bytes
5111c4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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)