如何访问 JpCap 数据包中的数据包信息 [英] How can you access the packet information in a JpCap Packet

查看:73
本文介绍了如何访问 JpCap 数据包中的数据包信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I pull relevant packet information from a JpCap packet? I am trying to find the source/destination ip and port. So far I have tried string parsing the Packet's toString() method, but that seems brutish.

推荐答案

您必须将 Packet 对象强制转换为我认为正确的 Packet 类型.

You have to cast the Packet object to the correct type of Packet i think.

比如:

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 数据包中的数据包信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆