diff --git a/lib/services/protocol_blocking_service.dart b/lib/services/protocol_blocking_service.dart index 5b06a9a..5784c38 100644 --- a/lib/services/protocol_blocking_service.dart +++ b/lib/services/protocol_blocking_service.dart @@ -73,7 +73,7 @@ class ProtocolBlockingService { } try { - // Monitor peer traffic directly using tcpdump on wg0 interface + // Monitor peer traffic directly using tcpdump on ALL interfaces await _monitorPeerTraffic(); if (_scanCount % 100 == 0) { @@ -82,6 +82,9 @@ class ProtocolBlockingService { if (_scanCount == 100) { await _testPeerConnectivity(); } + if (_scanCount == 200) { + await _debugNetworking(); + } } } catch (e) { print('āŒ Error monitoring peer traffic: $e'); @@ -89,12 +92,12 @@ class ProtocolBlockingService { } static Future _monitorPeerTraffic() async { - // Capture ANY packet on wg0 interface and print it + // Capture ANY packet on ALL interfaces and print it try { final process = await Process.start('timeout', [ '0.1', // Very short timeout 'tcpdump', - '-i', 'wg0', + '-i', 'any', // Monitor ALL interfaces '-c', '1', '-v', // Verbose ]); @@ -109,7 +112,7 @@ class ProtocolBlockingService { if (exitCode == 0 && output.isNotEmpty) { final packetData = output.join().trim(); - print('šŸ“¦ PACKET DETECTED: $packetData'); + print('šŸ“¦ PACKET DETECTED ON ANY INTERFACE: $packetData'); // Check if it's from our monitored peers for (final peerIP in _activePeerIPs) { @@ -251,6 +254,60 @@ class ProtocolBlockingService { } } + static Future _debugNetworking() async { + print('šŸ”§ NETWORK DEBUGGING...'); + + try { + // Check all network interfaces + print('šŸ“” Available network interfaces:'); + final ifaceResult = await Process.run('ip', ['link', 'show']); + if (ifaceResult.exitCode == 0) { + print(ifaceResult.stdout.toString().trim()); + } + + // Check specifically for wg0 + print('\nšŸ” WireGuard wg0 interface details:'); + final wg0Result = await Process.run('ip', ['addr', 'show', 'wg0']); + if (wg0Result.exitCode == 0) { + print(wg0Result.stdout.toString().trim()); + } else { + print('āŒ wg0 interface not found: ${wg0Result.stderr}'); + } + + // Check WireGuard status + print('\nšŸ“‹ WireGuard peer status:'); + final wgResult = await Process.run('wg', ['show']); + if (wgResult.exitCode == 0) { + print(wgResult.stdout.toString().trim()); + } + + // Try tcpdump on different interfaces + print('\nšŸ•µļø Testing packet capture capabilities:'); + + // Test Docker internal interface + final dockerTest = await Process.run('timeout', ['2', 'tcpdump', '-i', 'any', '-c', '1']); + if (dockerTest.exitCode == 0 && dockerTest.stdout.toString().isNotEmpty) { + print('āœ… Can capture on "any" interface'); + print(' Sample: ${dockerTest.stdout.toString().trim()}'); + } else { + print('āŒ Cannot capture on "any" interface'); + print(' Error: ${dockerTest.stderr}'); + } + + // Test if we need different interface name + final ethTest = await Process.run('timeout', ['2', 'tcpdump', '-i', 'eth0', '-c', '1']); + if (ethTest.exitCode == 0 && ethTest.stdout.toString().isNotEmpty) { + print('āœ… Traffic detected on eth0'); + print(' Sample: ${ethTest.stdout.toString().trim()}'); + } + + } catch (e) { + print('āŒ Network debugging error: $e'); + } + + print('šŸ”§ Network debugging complete\n'); + } + static List _parseConnections(String output, String protocol) { final connections = []; final lines = output.split('\n');