如何使用 Java 监控 tcpflow 输出? 我尝试了以下方法,但它不适用于 tcp 流 -c arg。
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);
}
}
关于java - 使用 Java 监视 tcpflow 输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33358541/