CrazyEngineers
  • How to interpret packets?

    Manish Goyal

    Member

    Updated: Oct 11, 2024
    Views: 1.1K
    I have developed a program using JPCAP in java,which will capture packets and display it received by my pc but the problem is that output is not understandable by me

    when i execute that program and enter the url address in web browser say Google.com,it displays me output like this

    1277469255:706879
    1277469255:708581

    what does it means?Is there any possible way to extract header ,length ,type of packet and data that resides in that program


    This is my program
    import jpcap.*;
    import jpcap.packet.*;
    import java.io.*;
    import jpcap.packet.TCPPacket.*;
    import java.net.InetAddress;
    
    class NetworkList
    {
        public static void main(String args[])throws IOException
        {
            int i;
            try
            {
            NetworkInterface[] devices = JpcapCaptor.getDeviceList();
    
            for (i = 0; i < devices.length; i++)
             {
                  //print out its name and description
                  System.out.println(i+": "+devices[i].name + "(" + devices[i].description+")"+devices[i].loopback);
            }
    JpcapCaptor captor=JpcapCaptor.openDevice(devices[0], 65535, false, 20);
    for(i=0;i<10;i++){
    
    System.out.println(captor.getPacket());
    }
    
    captor.close();
    }
    catch(Exception e)
    {
    System.out.println(e.getMessage());
    }
    }
    }
    I have also tried using captor.getPacket().data ,but then it throws null exception
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Manish Goyal

    MemberJun 25, 2010

    guys i have achieved what i want 😀 I have used 2nd method ie callback method for this

    but still confused why there was exception in first case when i try to capture packets one by one
    Are you sure? This action cannot be undone.
    Cancel
  • durga ch

    MemberJun 27, 2010

    did you try to goggle then with the error message you received?

    To interpret packets may be you can refer to this thread #-Link-Snipped-#
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberJun 28, 2010

    yeah i had searched on google about this ..
    But the error was same that i commonly encountered during programming in java

    ie null
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberJun 28, 2010

    Now again there is new problem

    Previously when i was using my broadband connection for accessing internet .I was able to capture packets, received by my system.

    but now when i am accessing internet using my mobile as a modem(usb modem) ,i am not able to see even single packet .

    can anyone explain me what's the reason?
    Are you sure? This action cannot be undone.
    Cancel
  • durga ch

    MemberJun 28, 2010

    USB port numbers are different from your Ethernet port number right?
    can you explain your program above? I am a JAVA illeterate
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberJun 28, 2010

    I have used jpcap which is a open source library for capturing and sending packets from java applications

    To get the List of network Interfaces of my machine.jpcap provides JpcapCaptor.getDeviceList() method which is static method of JpcapCaptor class.It will return array of NetworkInterface objects and by using the fields of NetworkInterface class ,I can retrieve each and every information of networkinterface of my machine.

    JpcapCaptor captor=JpcapCaptor.openDevice(device[index], 65535, false, 20);

    Once we obtain the list of network interfaces and choose which network interface to capture packets from, you can open the interface by
    using jpcap.opendevice() method

    while calling openDevice(),we provide following parameters
    NetworkInterface interface:-NetworkInterface which you want to open
    int no:-Max no of bytes to cpature
    boolean promics :-Whether to open device in promiscuous mode or not
    int time_out:-to set capture time_out value

    Once you obtain an instance of of jpcapcaptor,you can capture packets from the interface.

    There are two major approaches to capture packets using a #-Link-Snipped-#
    instance: using a callback method, and capturing packets one-by-one

    In callback method we implement the interface named PacketReceiver then create a method named which will handle the packets gernerated

    For capturing packets we can use either processPacket() or loopPacket() method.

    For each captured packet it will call the method which i have created to handle that packet

    and in one by one approach .I will simply create a loop and capture packets by using getPacket() method

    I hope,you got an idea

    If still confused then post your query
    Are you sure? This action cannot be undone.
    Cancel
  • durga ch

    MemberJun 28, 2010

    alright
    By what you have said - since its our network interface device has changed < i think the problem might be here
    "while calling openDevice(),we provide following parameters
    NetworkInterface interface:-NetworkInterface which you want to open
    int no:-Max no of bytes to cpature

    boolean promics :-Whether to open device in promiscuous mode or not
    int time_out:-to set capture time_out value"

    this is a just a inference though.
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberJun 28, 2010

    But when i execute my program there is only one networkInterface it is showing on output, which i can open
    Are you sure? This action cannot be undone.
    Cancel
  • durga ch

    MemberJun 28, 2010

    ..and which network interface does it show?
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberJun 28, 2010

    VIA RHINE II Fast Ethernet Adapter
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberJun 28, 2010

    I think the problem is with net connection .I am not sure whether this program works on dial up connection or not
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register