Работа над фильтрацией через libpcap
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
package ru.serega6531.packmate.service;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.pcap4j.core.PcapNativeException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.serega6531.packmate.model.CtfService;
|
||||
import ru.serega6531.packmate.model.enums.SubscriptionMessageType;
|
||||
import ru.serega6531.packmate.model.pojo.SubscriptionMessage;
|
||||
import ru.serega6531.packmate.pcap.PcapWorker;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PcapService {
|
||||
|
||||
@Getter
|
||||
@@ -31,4 +37,18 @@ public class PcapService {
|
||||
}
|
||||
}
|
||||
|
||||
public void updateFilter(Collection<CtfService> services) {
|
||||
final String ports = services.stream()
|
||||
.map(CtfService::getPort)
|
||||
.map(p -> "port " + p)
|
||||
.collect(Collectors.joining(" or "));
|
||||
|
||||
final String format = "(tcp or udp) and (%s)";
|
||||
String filter = String.format(format, ports);
|
||||
|
||||
log.info("New filter: " + filter);
|
||||
|
||||
worker.setFilter(filter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user