Java 如何访问JpCap数据包中的数据包信息

Java 如何访问JpCap数据包中的数据包信息,java,networking,packet,packet-sniffers,jpcap,Java,Networking,Packet,Packet Sniffers,Jpcap,如何从JpCap数据包中提取相关数据包信息?我正在尝试查找源/目标ip和端口。到目前为止,我已经尝试过对数据包的toString()方法进行字符串解析,但这似乎很残忍。我认为必须将数据包对象转换为正确的数据包类型 比如: TCPPacket p = (TCPPacket)packet; // Get the tcp src and dest ports int destPort = p.dst_port; int srcPort = p.src_port; // Get the src an

如何从JpCap数据包中提取相关数据包信息?我正在尝试查找源/目标ip和端口。到目前为止,我已经尝试过对数据包的toString()方法进行字符串解析,但这似乎很残忍。

我认为必须将数据包对象转换为正确的数据包类型

比如:

TCPPacket p = (TCPPacket)packet;

// Get the tcp src and dest ports
int destPort = p.dst_port;
int srcPort = p.src_port;

// Get the src and dest IP addresses from the IP layer
InetAddress destIp = p.dst_ip;
InetAddress srcIp = p.src_ip;

下面是一个关于使用Jpcap数据包访问数据包信息的好方法

谢谢!你救了我这么多