Extracting packet details using jnetpcap library

user3823859

How to extract protocol field , source ip and destination ip from offline pcap file using jnetpcap library?

Aayush Rathore

For TCP/IP stack: We can get the protocols on the basis of port number of tcp header

Port numbers corresponding to different protocols are given on the following link: http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml

Getting protocol in jnetpap library ( http://jnetpcap.com ):

PcapPacket packet = //get from somewhere
Tcp tcp = new Tcp();
Ip4 ip = new IP4();
byte[] sIP = new byte[4];
byte[] dIP = new byte[4];
String sourceIP = "";
String destIP = "";

if(packet.hasHeader(ip) && packet.hasHeader(tcp)){
   sIP = packet.getHeader(ip).source();
   sourceIP = org.jnetpcap.packet.format.FormatUtils.ip(sIP);
   dIP = packet.getHeader(ip).destination();
   destIP = org.jnetpcap.packet.format.FormatUtils.ip(dIP);

   System.out.println("*" + sourceIP + "*" + destIP);
   System.out.println("Source IP" + sourceIP);
   System.out.println("Destination IP" + destIP);

   if(tcp.source() == 80){
      System.out.println("HTTP protocol");
   } else if(tcp.source == 23) {
      System.out.println("Telnet protocol");
   }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Pig: extracting email details from raw text using REGEX

From Dev

Extracting arguments using stringstream

From Dev

Extracting packet informations using C++

From Dev

How to get flow record details of a netflow packet

From Dev

Maintenance Table, presentation of Data using record details as column headers and extracting only most recent maintenance

From Dev

java error, jnetpcap library in eclipse

From Dev

Extracting packet details using jnetpcap library

From Dev

extracting a sentence using a tokenizer

From Dev

extracting the column using AWK

From Dev

Extracting a string using Regex

From Dev

Details About Glide Library

From Dev

Extracting <a> tags using BeautifulSoup

From Dev

Send and receive packet to and from nodes using pycore library in python script

From Dev

extracting a parameter using regexp

From Dev

Extracting packet informations using C++

From Dev

Why isnt the chosen device not opening in Jnetpcap (using eclipse)?

From Dev

Extracting RTP payload from packet

From Dev

extracting packet from frame winpcap

From Dev

Jnetpcap Payload modify in UDP packet

From Dev

extracting data using dplyr

From Dev

extracting json using jq

From Dev

Using Card-io library asks for card details instead of calling up the camera for scanning

From Dev

Python scapy extracting field from packet

From Dev

Extracting information using regex

From Dev

Extracting text using Xpath

From Dev

Extracting HTML from XML or JSON output using yahoo's HTMLSTRING and get some details from xml or json output

From Dev

Extracting Text Using BeautifulSoup

From Dev

Extracting packet loss data from ping result in python

From Dev

extracting tables using BeautifulSoup

Related Related

HotTag

Archive