473,403 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Tcpdump using Jpcap

hii, everybody how are you ?

Expand|Select|Wrap|Line Numbers
  1. import jpcap.*;
  2. import jpcap.packet.Packet;
  3. import java.io.BufferedWriter;
  4. import java.io.FileWriter;
  5. import java.io.IOException;
  6. import java.io.FileNotFoundException;
  7. import java.util.*;
  8. import java.sql.*;
  9.  
  10. class Test {
  11.     public static void main(String[] args) throws Exception {
  12.         NetworkInterface[] devices = JpcapCaptor.getDeviceList();
  13.  
  14.         if(args.length<1){
  15.             System.out.println("usage: java Tcpdump <select a number from the following>");
  16.  
  17.             for (int i = 0; i < devices.length; i++) {
  18.                 System.out.println(i+" :"+devices[i].name + "(" + devices[i].description+")");
  19.                 System.out.println("    data link:"+devices[i].datalink_name + "(" + devices[i].datalink_description+")");
  20.                 System.out.print("    MAC address:");
  21.                 for (byte b : devices[i].mac_address)
  22.                     System.out.print(Integer.toHexString(b&0xff) + ":");
  23.                 System.out.println();
  24.                 for (NetworkInterfaceAddress a : devices[i].addresses)
  25.                     System.out.println("    address:"+a.address + " " + a.subnet + " " + a.broadcast);
  26.             }
  27.         }else{
  28.             JpcapCaptor jpcap = JpcapCaptor.openDevice(devices[Integer.parseInt(args[0])], 65535, true, 0);
  29.             jpcap.setFilter("ip and tcp", true);
  30.  
  31.             for (int i = 0; i < 1000; i++) { 
  32.                 while (jpcap.getPacket() != null) {
  33.                     Packet prot2 = jpcap.getPacket();
  34.  
  35.                     byte[] d = prot2.data;
  36.                     byte[] h = prot2.header;
  37.  
  38.                     String p = new String(d);
  39.                         System.out.println("");
  40.  
  41.                     for(byte b: d) {
  42.                         System.out.print(Integer.toString(b, 16).toUpperCase());
  43.                     } 
  44.  
  45.                     System.out.println("");
  46.                     System.out.println("String form header:" + h);
  47.                     System.out.println("");
  48.                     String ss = prot2.toString();
  49.  
  50.                     if(prot2==null){
  51.                         continue;
  52.                     }
  53.  
  54.                     if(ss.contains("protocol(6)")){
  55.                         System.out.println("Received packet TCP :" + jpcap.getPacket());
  56.                     }
  57.                  }
  58.             }
  59.         }
  60.     }
  61. }
  62.  
guys the problem i have back there already solve, now with the code i post above i success build a simple tcpdump + reading packet header and payload...
now i want to try analysis the payload and header.. but don't know where i must start...
i'll appreciate who ever that told me where i must start..Thanks
Apr 4 '11 #1
0 2104

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Damien Legrand | last post by:
i use jpcap classe for captured packet but i don't arrive to save the packets in a file with the method jpcapwriter... i dont know java. help me ! thanks. class jpcapwriter doc : ...
2
by: ShawnD | last post by:
I'm having some issues when trying to read input off of a pipe using a python script. I'm trying to process packet data from tcpdump in real-time, so it's a filter that needs to read data while the...
2
by: missolsr | last post by:
hi, I am using jpcap to capture OLSR topology control (udp) packets. Does anyone know how to extract data (the way ethereal does it) from the olsr packet? There are methods to extract data...
1
by: faize | last post by:
I want to Write a _real time_ perl program that will take the output of tcpdump in ASCII format. Every second this program will output to screen the average number of packets as well as the average...
7
ashitpro
by: ashitpro | last post by:
I have two interfaces eth3 and eth4 both have been added to bridge br1 Also eth1 and eth2 are added to bridge br0. eth3/eth4/br1 don't have any ip addresses..i.e. 0.0.0.0 Problem is.. I am able to...
0
by: Ludwig von DOHWEE | last post by:
Hello , I am newbie and need a help. How to run and control TCPDUMP (or application program ) via python script ? I want to run TCPDUMP program and save some file through it. import os...
2
by: Gurpreet Singhh | last post by:
I need to select maximum of the Emp_id values from SQL server 2005 table.I was using the command which selects max value till 10 but after that it fails to pick max value of emp id from the...
4
by: bommanaboyina | last post by:
iam using textbox1,textbox2,textbox3 for Empid,Ename,Esalary and iam upadting the data using update button for that im using stored procedure for updating ename esalary and the problem is some...
1
by: Shun | last post by:
Hello, I am trying to extract the data from my Oracle 10g database using Java. First, I tried to connect Oracle to Java using this code and it works. import java.util.*; import java.sql.*;...
3
by: evenstar | last post by:
As I know"A nonstatic data member may not be used as a default argument because its value cannot be used independently of the object of which it is a part. Using a nonstatic data member as a default...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.