简体   繁体   English

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

[英]How can you access the packet information in a JpCap Packet

How can I pull relevant packet information from a JpCap packet? 如何从JpCap数据包中提取相关的数据包信息? I am trying to find the source/destination ip and port. 我试图找到源/目标IP和端口。 So far I have tried string parsing the Packet's toString() method, but that seems brutish. 到目前为止,我已经尝试过对Packet的toString()方法进行字符串解析,但这看起来很粗糙。

You have to cast the Packet object to the correct type of Packet i think. 您必须将Packet对象转换为我认为的正确类型的Packet。

So something like: 所以类似于:

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 Packet访问数据包信息的好例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM