Enhance Dockerfile to include tcpdump for network monitoring

This commit is contained in:
ImBenji
2025-08-29 00:22:49 +01:00
parent 929dfafe78
commit 88ab9cf2e3

View File

@@ -34,27 +34,48 @@ class ProtocolBlockingService {
}
static void _startConnectionMonitoring() {
print('📡 Starting connection monitoring timer (100ms intervals)...');
_monitorTimer = Timer.periodic(Duration(milliseconds: 100), (_) async {
await _scanForNewConnections();
});
}
static Future<void> _scanForNewConnections() async {
static int scanCount = 0;
scanCount++;
try {
// Monitor both TCP and UDP connections
final tcpResult = await Process.run('ss', ['-tnp', 'state', 'syn-sent,established']);
final udpResult = await Process.run('ss', ['-unp']);
if (scanCount % 100 == 0) { // Log every 10 seconds
print('🔍 Scan #$scanCount - TCP exit code: ${tcpResult.exitCode}, UDP exit code: ${udpResult.exitCode}');
}
if (tcpResult.exitCode != 0) {
print('❌ TCP ss command failed: ${tcpResult.stderr}');
return;
}
if (udpResult.exitCode != 0) {
print('❌ UDP ss command failed: ${udpResult.stderr}');
return;
}
final tcpConnections = _parseConnections(tcpResult.stdout.toString(), 'tcp');
final udpConnections = _parseConnections(udpResult.stdout.toString(), 'udp');
if (scanCount % 100 == 0) {
print('🔍 Found ${tcpConnections.length} TCP + ${udpConnections.length} UDP connections');
}
for (final conn in [...tcpConnections, ...udpConnections]) {
if (_isNewConnection(conn)) {
await _handleNewConnection(conn);
}
}
} catch (e) {
print('Error scanning for connections: $e');
print('Error scanning for connections: $e');
}
}