【问题标题】:tshark command line to convert a wireskark pcap file to a text filetshark 命令行将wireskark pcap文件转换为文本文件
【发布时间】:2016-09-06 23:26:33
【问题描述】:

我正在尝试使用 tshark 命令行将wireskark pcap 文件转换为文本文件。一切看起来都不错。但我没有输出,也没有错误

public void convertPcapToTxt( )  {
  try {
    // setting output and input file names
    String resultfile = "C:\\MY.txt";
    String pcapfile = "C:\\MY.pcap";
    Runtime rt = Runtime.getRuntime();
    // create output
    PrintStream out = new PrintStream(resultfile);
    // set command line
    Process proc = rt.exec("tshark.exe -V -r " + pcapfile);
    //output to file
    BufferedReader stdInput = new BufferedReader
                             (new InputStreamReader(proc.getInputStream()));
     String s = null;
     while ((s = stdInput.readLine()) != null) {
      out.println(s);
     }
   //close output
   out.close();
   } catch (IOException io) {
      io.printStackTrace();
   } 
}

【问题讨论】:

  • 如果您尝试命令“tshark.exe -v”(小写“v”)会打印什么?如果 that 什么也没打印,可能是找不到 TShark 可执行文件。
  • 当我从命令行运行此命令时,它运行良好“tshark.exe -V -r C:\MY.pcap”,因此它正在查找 tshark 并将其显示到我的屏幕上。我什至可以执行“tshark.exe -V -r C:\MY.pcap > C:\MY.txt”;并获得一个好的文本文件。我已经尝试在 java 中对其进行硬编码,但仍然没有输出或错误
  • 也仅供参考。我有相同的代码工作,但使用将 pcap 转换为 xml 的命令。它运行良好。

标签: pcap


【解决方案1】:
public void convertPcapToTxt(File file, String pcapfile) {
  try {
    PrintStream out = new PrintStream(new FileOutputStream(file));
    Runtime rt = Runtime.getRuntime();
    String commands = "tshark.exe -V -r \"" + pcapfile + "\"";
    Process proc = rt.exec(commands);
    BufferedReader stdInput = new BufferedReader
                             (new InputStreamReader(proc.getInputStream()));

    String s = null;
    while ((s = stdInput.readLine()) != null) {
        out.println(s);
    }
    out.close();
  } catch (IOException io) {
     io.printStackTrace();
  }
}

【讨论】:

  • 将 pcap 转换为 XML。将 -V 替换为“-T pdml”
猜你喜欢
  • 2021-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-15
  • 2017-03-25
  • 1970-01-01
  • 2021-12-05
  • 2018-10-23
相关资源
最近更新 更多