| 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") | |