我在 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);
}
}
}
任何帮助,将不胜感激。