File size: 1,783 Bytes
6c0af85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
import socket
import ssl

def test_tcp_connection(host, port):
    """Test basic TCP connection to host:port"""
    print(f"Testing TCP connection to {host}:{port}...")
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(10)
        result = sock.connect_ex((host, port))
        sock.close()
        
        if result == 0:
            print("βœ… TCP connection successful")
            return True
        else:
            print(f"❌ TCP connection failed with error code: {result}")
            return False
    except Exception as e:
        print(f"❌ TCP connection failed: {e}")
        return False

def test_ssl_connection(host, port):
    """Test SSL connection to host:port"""
    print(f"Testing SSL connection to {host}:{port}...")
    try:
        context = ssl.create_default_context()
        with socket.create_connection((host, port), timeout=10) as sock:
            with context.wrap_socket(sock, server_hostname=host) as ssock:
                print(f"βœ… SSL connection successful")
                print(f"SSL version: {ssock.version()}")
                return True
    except Exception as e:
        print(f"❌ SSL connection failed: {e}")
        return False

if __name__ == "__main__":
    host = 'redis-16717.c85.us-east-1-2.ec2.redns.redis-cloud.com'
    port = 16717
    
    print("=== Network Connectivity Tests ===")
    
    tcp_result = test_tcp_connection(host, port)
    print()
    ssl_result = test_ssl_connection(host, port)
    
    print("\n=== Summary ===")
    if tcp_result and ssl_result:
        print("βœ… All network tests passed")
    elif tcp_result:
        print("⚠️  TCP connection works but SSL failed")
    else:
        print("❌ Network connectivity issues detected")