简体   繁体   English

Java PCAP文件解析器库

[英]Java PCAP file parser library

I'm looking for a fast way to parse PCAP file packets. 我正在寻找一种快速解析PCAP文件包的方法。

I'm currently using jNetPcap like so: 我目前正在使用jNetPcap

Pcap pcap = Pcap.openOffline(file, errbuf);
pcap.loop(10, jpacketHandler, "jNetPcap rocks!");

But it is pretty slow, is there any other good Java libraries that can parse PCAP files? 但它很慢,有没有其他优秀的Java库可以解析PCAP文件?

Just stumbled upon pcap parsing task in Java and found a pcap parser in Kaitai Struct . 只是偶然发现了Java中的pcap解析任务,并在Kaitai Struct中找到了一个pcap解析器 Surprisingly, it turns out to be blazing fast — probably because it's not a wrapper over C pcap library, but just a raw parser instead. 令人惊讶的是,它变得非常快 - 可能是因为它不是C pcap库的包装器,而只是一个原始解析器。 My average results (on the same box, of course) are as following: 我的平均结果(当然在同一个方框中)如下:

  • jpcap - 10,301 pps jpcap - 10,301 pps
  • jnetpcap - 15,148 pps jnetpcap - 15,148 pps
  • pcap.ksy in Kaitai Struct - 121,176 pps 在Kaitai Struct的pcap.ksy - 121,176 pps

So, if you don't need capturing , I wholeheartedly recommend trying out Kaitai Struct parser. 因此,如果您不需要捕获 ,我会全心全意地推荐尝试使用Kaitai Struct解析器。

jNetPcap is the most stable and well written wrapper. jNetPcap是最稳定,写得最好的包装器。 Its better than JPcap see this for comparison details. 它优于JPCAP看到这个比较细节。 And i don't have a comparison details for pcap4j to evaluate. 我没有评估pcap4j的比较细节。

You can use Jxnet . 您可以使用Jxnet Like jnetpcap, Jxnet use direct buffer to minimized unnecessary memory copy, Jxnet also use netty-buffer (UnsafeBuffer) for decoding and encoding packet. 与jnetpcap一样, Jxnet使用直接缓冲区来最小化不必要的内存复制, Jxnet也使用netty -buffer (UnsafeBuffer)来解码和编码数据包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM