How can you access the packet information in a JpCap Packet

人盡茶涼 提交于 2019-12-13 15:10:14

问题


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.


回答1:


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

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;



回答2:


Here is a good example about accessing packets information using Jpcap Packet



来源:https://stackoverflow.com/questions/2642487/how-can-you-access-the-packet-information-in-a-jpcap-packet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!