@@ -0,0 +1,2883 @@
+import org.pcap4j.core.*;%0Aimport org.pcap4j.packet.Packet;%0Aimport org.pcap4j.util.NifSelector;%0A%0Aimport java.io.IOException;%0A%0A/**%0A * dump packets%0A */%0Apublic class PacketDump %7B%0A%0A    private static final String COUNT_KEY= %22count%22;%0A    private static final int COUNT%0A            = Integer.getInteger(COUNT_KEY, 5);%0A%0A    private static final String READ_TIMEOUT_KEY = %22readTimeout%22;%0A    private static final int READ_TIMEOUT%0A            = Integer.getInteger(READ_TIMEOUT_KEY, 10); // %5Bms%5D%0A%0A    private static final String SNAPLEN_KEY = %22snaplen%22;%0A    private static final int SNAPLEN%0A            = Integer.getInteger(SNAPLEN_KEY, 65536); // %5Bbytes%5D%0A%0A    private static final String TIMESTAMP_PRECISION_NANO_KEY = %22timestampPrecision.nano%22;%0A    private static final boolean TIMESTAMP_PRECISION_NANO%0A            = Boolean.getBoolean(TIMESTAMP_PRECISION_NANO_KEY);%0A%0A    private static final String PCAP_FILE_KEY = %22pcapFile%22;%0A    private static final String PCAP_FILE%0A            = System.getProperty(PCAP_FILE_KEY, %22Dump.pcap%22);%0A%0A    private PacketDump() %7B%0A    %7D%0A%0A    public static void main(String%5B%5D args) throws PcapNativeException, NotOpenException %7B%0A        String filter = args.length != 0 ? args%5B0%5D : %22%22;%0A%0A        System.out.println(COUNT_KEY + %22: %22 + COUNT);%0A        System.out.println(READ_TIMEOUT_KEY + %22: %22 + READ_TIMEOUT);%0A        System.out.println(SNAPLEN_KEY + %22: %22 + SNAPLEN);%0A        System.out.println(TIMESTAMP_PRECISION_NANO_KEY + %22: %22 + TIMESTAMP_PRECISION_NANO);%0A        System.out.println(%22%5Cn%22);%0A%0A        PcapNetworkInterface nif;%0A        try %7B%0A            nif = new NifSelector().selectNetworkInterface();%0A        %7D%0A        catch (IOException e) %7B%0A            e.printStackTrace();%0A            return;%0A        %7D%0A%0A        if (nif == null) %7B%0A            return;%0A        %7D%0A%0A        System.out.println(nif.getName() + %22(%22 + nif.getDescription() + %22)%22);%0A%0A        PcapHandle.Builder phb%0A                = new PcapHandle.Builder(nif.getName())%0A                .snaplen(SNAPLEN)%0A                .promiscuousMode(PcapNetworkInterface.PromiscuousMode.PROMISCUOUS)%0A                .timeoutMillis(READ_TIMEOUT);%0A        if (TIMESTAMP_PRECISION_NANO) %7B%0A            phb.timestampPrecision(PcapHandle.TimestampPrecision.NANO);%0A        %7D%0A        PcapHandle handle = phb.build();%0A%0A        handle.setFilter(%0A                filter,%0A                BpfProgram.BpfCompileMode.OPTIMIZE%0A        );%0A%0A        int num = 0;%0A        PcapDumper dumper = handle.dumpOpen(PCAP_FILE);%0A        while (true) %7B%0A            Packet packet = handle.getNextPacket();%0A            if (packet == null) %7B%0A                continue;%0A            %7D%0A            else %7B%0A                dumper.dump(packet, handle.getTimestamp());%0A                num++;%0A                if (num %3E= COUNT) %7B%0A                    break;%0A                %7D%0A            %7D%0A        %7D%0A%0A        dumper.close();%0A        handle.close();%0A    %7D%0A%0A%7D%0A

add a class to do packet dump