用Java监视tcpflow输出?
如何使用Java监控tcpflow输出? 我尝试了以下方法,但它不适用于tcp流-carg用Java监视tcpflow输出?,java,tcpdump,Java,Tcpdump,如何使用Java监控tcpflow输出? 我尝试了以下方法,但它不适用于tcp流-carg Process process; try { process = Runtime.getRuntime().exec("tcpflow -c"); InputStreamReader ir = new InputStreamReader(process.getInputStream()); LineNumberReader input = new LineNumberR
Process process;
try {
process = Runtime.getRuntime().exec("tcpflow -c");
InputStreamReader ir = new
InputStreamReader(process.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
String line;
while ((line = input.readLine()) != null) {
System.out.println("Output: " + line);
}
} catch (IOException e) {
e.printStackTrace();
}
为什么tcpflow的输出没有被读取?但是,如果执行tcpflow-h,则会读取输出。通过跟踪tcpflow中的日志文件找到了解决方法
public static void main(String[] args) {
File log = new File("packets.log");
PacketListener listener = new PacketListener();
Tailer tailer = Tailer.create(log, listener, 2500);
tailer.run();
}
还有跟踪它的班级
public class PacketListener extends TailerListenerAdapter {
@Override
public void handle(String line) {
System.out.println("Inbound: " + line);
}
}