Expand|Select|Wrap|Line Numbers
- import jpcap.*;
- import jpcap.packet.Packet;
- import java.io.BufferedWriter;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.FileNotFoundException;
- import java.util.*;
- import java.sql.*;
- class Test {
- public static void main(String[] args) throws Exception {
- NetworkInterface[] devices = JpcapCaptor.getDeviceList();
- if(args.length<1){
- System.out.println("usage: java Tcpdump <select a number from the following>");
- for (int i = 0; i < devices.length; i++) {
- System.out.println(i+" :"+devices[i].name + "(" + devices[i].description+")");
- System.out.println(" data link:"+devices[i].datalink_name + "(" + devices[i].datalink_description+")");
- System.out.print(" MAC address:");
- for (byte b : devices[i].mac_address)
- System.out.print(Integer.toHexString(b&0xff) + ":");
- System.out.println();
- for (NetworkInterfaceAddress a : devices[i].addresses)
- System.out.println(" address:"+a.address + " " + a.subnet + " " + a.broadcast);
- }
- }else{
- JpcapCaptor jpcap = JpcapCaptor.openDevice(devices[Integer.parseInt(args[0])], 65535, true, 0);
- jpcap.setFilter("ip and tcp", true);
- for (int i = 0; i < 1000; i++) {
- while (jpcap.getPacket() != null) {
- Packet prot2 = jpcap.getPacket();
- byte[] d = prot2.data;
- byte[] h = prot2.header;
- String p = new String(d);
- System.out.println("");
- for(byte b: d) {
- System.out.print(Integer.toString(b, 16).toUpperCase());
- }
- System.out.println("");
- System.out.println("String form header:" + h);
- System.out.println("");
- String ss = prot2.toString();
- if(prot2==null){
- continue;
- }
- if(ss.contains("protocol(6)")){
- System.out.println("Received packet TCP :" + jpcap.getPacket());
- }
- }
- }
- }
- }
- }
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