Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By Fubarable

Thread: JPCap - cant capture TCP packets

  1. #1
    da-cena-fan is offline Member
    Join Date
    Aug 2012
    Posts
    1
    Rep Power
    0

    Default JPCap - cant capture TCP packets

    I'm trying to implement a network sniffer using JPCap library.

    The problem is, it is capturing only UDP packets of other nodes. The TCP packets are not being captured. (Actually TCP packets of my computer ONLY are being sniffed)

    This is the code I'm using:
    Java Code:
    import java.io.IOException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import jpcap.JpcapCaptor;
    import jpcap.NetworkInterface;
    
    /**
    *
    * @author Ruchira
    */
    public class SnifferExample {
    
    JpcapCaptor captor;
    NetworkInterface[] interfaceList;
    
    //Change this number according to the Network Interface which you wish to Sniff
    private static final int interfaceNumber=1;
    
    public static void main(String[] str) {
    SnifferExample sniff=new SnifferExample();
    sniff.printNetworkInterfaceList();
    try {
    sniff.capture();
    } catch (IOException ex) {
    Logger.getLogger(SnifferExample.class.getName()).log(Level.SEVERE, null, ex);
    }
    }
    
    /**
    * Run this method first and it will list out the available network interfaces in your computer
    * All of the interfaces will be put into an array (interfaceList)
    */
    public void printNetworkInterfaceList() {
    
    interfaceList = JpcapCaptor.getDeviceList();
    
    System.out.println("Number of Network Interfaces Found :"+interfaceList.length);
    
    for (int i = 0; i < interfaceList.length; i++) {
    System.out.println("Index :" + i + ", Network Device Name :" + interfaceList[i].name + ", Description :" +
    " " + interfaceList[i].description);
    }
    }
    
    public void capture() throws IOException {
    
    captor=JpcapCaptor.openDevice(interfaceList[interfaceNumber], 65535, true, 20000);
    captor.loopPacket(-1, new PacketPrinter());
    }
    }
    Java Code:
    import jpcap.PacketReceiver;
    import jpcap.packet.Packet;
    
    /**
    *
    * @author Ruchira
    */
    public class PacketPrinter implements PacketReceiver{
    
    public void receivePacket(Packet pkt) {
    System.out.println("Paket :"+pkt.toString());
    }
    
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Replies: 0
    Last Post: 07-28-2012, 11:02 AM
  2. capture packets from a specific Socket(s)?
    By theChameleon in forum Advanced Java
    Replies: 0
    Last Post: 11-14-2011, 04:32 AM
  3. help for jpcap
    By prashant in forum Networking
    Replies: 1
    Last Post: 02-02-2009, 05:01 PM
  4. about using jpcap
    By prashant in forum Networking
    Replies: 1
    Last Post: 12-28-2008, 05:28 PM
  5. How to capture IP packets
    By Hasan in forum Networking
    Replies: 1
    Last Post: 05-31-2007, 06:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •