3

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.

Mantas Vidutis
  • 16,376
  • 20
  • 76
  • 92

2 Answers2

4

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;
Binary Nerd
  • 13,872
  • 4
  • 42
  • 44
1

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

Nadya Nux
  • 519
  • 1
  • 5
  • 17