Refactor packet monitoring to capture all traffic on wg0 and enhance logging for peer traffic detection
This commit is contained in:
@@ -89,16 +89,14 @@ class ProtocolBlockingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> _monitorPeerTraffic() async {
|
static Future<void> _monitorPeerTraffic() async {
|
||||||
for (final peerIP in _activePeerIPs) {
|
// Capture ANY packet on wg0 interface and print it
|
||||||
try {
|
try {
|
||||||
// Capture any new outbound traffic from this peer
|
|
||||||
final process = await Process.start('timeout', [
|
final process = await Process.start('timeout', [
|
||||||
'0.1', // Very short timeout - just check for new packets
|
'0.1', // Very short timeout
|
||||||
'tcpdump',
|
'tcpdump',
|
||||||
'-i', 'wg0',
|
'-i', 'wg0',
|
||||||
'-c', '1',
|
'-c', '1',
|
||||||
'-l', // Line buffered
|
'-v', // Verbose
|
||||||
'src $peerIP and (tcp[tcpflags] & tcp-syn != 0 or udp)',
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
final output = <String>[];
|
final output = <String>[];
|
||||||
@@ -110,14 +108,22 @@ class ProtocolBlockingService {
|
|||||||
process.kill();
|
process.kill();
|
||||||
|
|
||||||
if (exitCode == 0 && output.isNotEmpty) {
|
if (exitCode == 0 && output.isNotEmpty) {
|
||||||
final packetData = output.join();
|
final packetData = output.join().trim();
|
||||||
|
print('📦 PACKET DETECTED: $packetData');
|
||||||
|
|
||||||
|
// Check if it's from our monitored peers
|
||||||
|
for (final peerIP in _activePeerIPs) {
|
||||||
|
if (packetData.contains(peerIP)) {
|
||||||
|
print('🎯 PEER TRAFFIC FROM $peerIP: $packetData');
|
||||||
await _analyzeNewPacket(packetData, peerIP);
|
await _analyzeNewPacket(packetData, peerIP);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Ignore timeout errors - normal when no new packets
|
// Ignore timeout errors - normal when no packets
|
||||||
if (!e.toString().contains('timeout')) {
|
if (!e.toString().contains('timeout') && !e.toString().contains('No such device')) {
|
||||||
print('❌ Error monitoring peer $peerIP: $e');
|
print('❌ Error monitoring traffic: $e');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user