Refactor connection scanning logic to use a static scan count variable

This commit is contained in:
ImBenji
2025-08-29 00:32:35 +01:00
parent 88ab9cf2e3
commit 2f845e0e3a

View File

@@ -40,17 +40,18 @@ class ProtocolBlockingService {
});
}
static int _scanCount = 0;
static Future<void> _scanForNewConnections() async {
static int scanCount = 0;
scanCount++;
_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 (_scanCount % 100 == 0) { // Log every 10 seconds
print('🔍 Scan #$_scanCount - TCP exit code: ${tcpResult.exitCode}, UDP exit code: ${udpResult.exitCode}');
}
if (tcpResult.exitCode != 0) {
@@ -65,7 +66,7 @@ class ProtocolBlockingService {
final tcpConnections = _parseConnections(tcpResult.stdout.toString(), 'tcp');
final udpConnections = _parseConnections(udpResult.stdout.toString(), 'udp');
if (scanCount % 100 == 0) {
if (_scanCount % 100 == 0) {
print('🔍 Found ${tcpConnections.length} TCP + ${udpConnections.length} UDP connections');
}