0

我在 Ubuntu 16.04 X86 上使用 Jpcap ver.0.7 (Keita Fujii) 库,我正在尝试使用提取数据包有效负载数据,getTCPData()但该方法丢失。

这是我的代码

import java.io.BufferedOutputStream;
import jpcap.PacketReceiver;
import jpcap.packet.ICMPPacket;
import jpcap.packet.IPPacket;
import jpcap.packet.Packet;
import jpcap.packet.TCPPacket;
import jpcap.packet.UDPPacket;

class PacketPrinter implements PacketReceiver, PacketListener {
    //this method is called every time Jpcap captures a packet


@Override
public void receivePacket(Packet packet) {
    if (packet instanceof TCPPacket) {
        TCPPacket pac = (TCPPacket) packet;
        byte[] data;
        data = pac.getTCPData();

        System.out.println("TCP ~~ Src: " + pac.src_ip + " Dest: " + pac.dst_ip + " dest port : " + pac.dst_port + " src port : " + pac.src_port);

    } else if (packet instanceof UDPPacket) {
        UDPPacket pac = (UDPPacket) packet;
        pac.
        System.out.println("UDP ~~ Src: " + pac.src_ip + " Dest: " + pac.dst_ip + " dest port : " + pac.dst_port + " src port : " + pac.src_port);

    } else if (packet instanceof ICMPPacket) {
        ICMPPacket pac = (ICMPPacket) packet;
        System.out.println("ICMP ~~ Src: " + pac.src_ip + " Dest: " + pac.dst_ip);

    } else if (packet instanceof IPPacket) {
        IPPacket pac = (IPPacket) packet;
        System.out.println("IP ~~ Src: " + pac.src_ip + " Dest: " + pac.dst_ip);

    }
}
}

任何帮助,将不胜感激。

4

1 回答 1

1

实际上有两个同名的类似项目:

  • 藤井凯太的 Jpcap
  • sourceforge 上的 Jpcap

它们是独立开发的,我使用的是第一个,这就是缺少这种方法的原因。sourceforge 上的 Jpcap 具有更多功能。

于 2017-05-04T01:50:21.867 回答