#!/usr/bin/env python3
"""
Test connectivity from Windows host to both routers
"""
import subprocess
import platform
def run_command(cmd):
"""Run shell command and return output"""
try:
result = subprocess.run(
cmd,
shell=True,
capture_output=True,
text=True,
timeout=10
)
return result.stdout + result.stderr
except subprocess.TimeoutExpired:
return "Command timed out"
except Exception as e:
return f"Error: {e}"
def test_connectivity():
"""Test network connectivity"""
print("=" * 60)
print("π Testing Network Connectivity")
print("=" * 60)
# Determine ping command based on OS
is_windows = platform.system().lower() == "windows"
ping_count = "-n 2" if is_windows else "-c 2"
# Test 1: Ping R1
print("\n1οΈβ£ Testing connectivity to R1 (192.168.242.129)...")
print("=" * 60)
output = run_command(f"ping {ping_count} 192.168.242.129")
print(output)
if "TTL=" in output or "ttl=" in output:
print("β
R1 is reachable!")
else:
print("β Cannot reach R1")
print("β οΈ This is a critical issue - MCP server needs R1 access")
return False
# Test 2: Ping R2
print("\n2οΈβ£ Testing connectivity to R2 (10.1.1.2)...")
print("=" * 60)
output = run_command(f"ping {ping_count} 10.1.1.2")
print(output)
if "TTL=" in output or "ttl=" in output:
print("β
R2 is reachable!")
r2_reachable = True
else:
print("β Cannot reach R2")
print("β οΈ This needs to be fixed for 2-router topology")
r2_reachable = False
# Test 3: Check routing table
print("\n3οΈβ£ Checking Windows routing table...")
print("=" * 60)
if is_windows:
output = run_command("route print | findstr 10.1.1")
else:
output = run_command("ip route | grep 10.1.1")
if output.strip():
print("β
Route to 10.1.1.0/24 exists:")
print(output)
else:
print("β No route to 10.1.1.0/24 found")
print("\nπ‘ FIX: Add route with this command:")
if is_windows:
print(" route add 10.1.1.0 mask 255.255.255.0 192.168.242.129")
else:
print(" sudo ip route add 10.1.1.0/24 via 192.168.242.129")
# Test 4: Traceroute to R2
if not r2_reachable:
print("\n4οΈβ£ Traceroute to R2 (to diagnose where packets are lost)...")
print("=" * 60)
if is_windows:
output = run_command("tracert -d -h 3 10.1.1.2")
else:
output = run_command("traceroute -n -m 3 10.1.1.2")
print(output)
if "192.168.242.129" in output:
print("\nπ‘ ANALYSIS:")
print(" β
Packets reach R1 (192.168.242.129)")
print(" β R1 is not forwarding to R2")
print("\nπ§ FIX: Enable Proxy ARP on R1:")
print(" python fix_r1_forwarding.py")
else:
print("\nπ‘ ANALYSIS:")
print(" β Packets don't even reach R1")
print(" β οΈ Problem with Windows routing or firewall")
# Summary
print("\n" + "=" * 60)
print("π CONNECTIVITY SUMMARY")
print("=" * 60)
print(f"R1 (192.168.242.129): {'β
OK' if True else 'β FAILED'}")
print(f"R2 (10.1.1.2): {'β
OK' if r2_reachable else 'β FAILED'}")
if r2_reachable:
print("\nπ ALL TESTS PASSED!")
print("\nπ NEXT STEP:")
print(" Update config.py and test MCP connection:")
print(" python test_jumphost.py")
else:
print("\nβ οΈ R2 NOT REACHABLE")
print("\nπ RECOMMENDED FIX:")
print(" 1. Run: python fix_r1_forwarding.py")
print(" 2. Test again: python test_connectivity.py")
print("=" * 60)
return r2_reachable
if __name__ == "__main__":
test_connectivity()