Java 网络数据分析包 JNetStream

fmms 13年前
     JNetStream 是一个用 Java 语言开发的网络数据包分析类库,同时也提供了一个分析工具。可以通过内置的NPL语言定义自己需要的协议 (比如可用NPL定义RTP与SIP协议),NPL的语法与Java/C相似。JNetStream还提供一个NPL语言调试器。    <br />    <pre class="brush:java; toolbar: true; auto-links: false;">package org.jnetstream.example;  import java.io.File; import java.io.IOException; import java.nio.ByteBuffer;  import org.jnetpcap.packet.JMemoryPacket; import org.jnetpcap.packet.PeeringException; import org.jnetpcap.protocol.JProtocol; import org.jnetstream.capture.Captures; import org.jnetstream.capture.FileFormatException; import org.jnetstream.capture.FileMode; import org.jnetstream.capture.file.RecordIndexer; import org.jnetstream.capture.file.pcap.PcapFile; import org.jnetstream.capture.file.pcap.PcapRecord;  /**  * A little test program to see what it would take to use jNetPcap to decode  * jNetStream read packets. We take a pcap capture file, open it for read-write  * with memory mapping so that we can peer natively with the underlying data.  *   * @author Mark Bednarczyk  * @author Sly Technologies, Inc.  */ public class DecodeUsingJNetPcap {   /**   * Entry point.   *    * @param args   *          ignored   */  public static void main(String[] args) {    try {    PcapFile pcap =        Captures.openFile(PcapFile.class, new File("tests/test-l2tp.pcap"),            FileMode.ReadWriteWithMap);     RecordIndexer records = pcap.getRecordIndexer();     long count = pcap.getPacketCount();     for (long i = 1; i < count; i++) {      PcapRecord record = records.get(i);     ByteBuffer b = record.getRecordBuffer();      JMemoryPacket packet = new JMemoryPacket(JProtocol.ETHERNET_ID, b);      System.out.println(packet);    }     pcap.close();    } catch (FileFormatException e) {    e.printStackTrace();   } catch (IOException e) {    e.printStackTrace();   } catch (PeeringException e) {    e.printStackTrace();   }  } }</pre>    <br />    <p><strong>项目主页:</strong><a href="http://www.open-open.com/lib/view/home/1326808906640" target="_blank">http://www.open-open.com/lib/view/home/1326808906640</a></p>