Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: jpcap packet captor cant capture packet

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default jpcap packet captor cant capture packet

    hi,
    i am developing intrusion detection system for that reason i am using jpcap packet capturing tool but at run time i am getting following error massage
    java.lang.NoSuchMethodError: setRoutingOption
    at jpcap.JpcapCaptor.nativeOpenLive(Native Method)
    at jpcap.JpcapCaptor.openDevice(JpcapCaptor.java:62)
    at c45.packet.PacketSniffer.startCapture(PacketSniffe r.java:36)
    at Main$1.run(Main.java:66)
    at java.lang.Thread.run(Thread.java:619)

    can any body plz help to reslove this error
    thank you for help..


    here's my code
    package c45.packet;

    import c45.database.*;
    import c45.algorithm.binary.*;
    import java.io.*;
    import java.sql.SQLException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import jpcap.*;
    import jpcap.packet.*;


    public class PacketSniffer { //implements Runnable {

    JpcapCaptor jpcap;
    FileWriter filewriter;
    NetworkInterface[] devices = JpcapCaptor.getDeviceList();
    TCPAnalyzer tcp = new TCPAnalyzer();
    UDPAnalyzer udp = new UDPAnalyzer();
    Calculation cal = new Calculation();
    Database db;
    private String s1="";
    private String s3="";


    // public static boolean ATTACK_DETECTED = false;
    public void startCapture() throws SQLException {
    try {
    try {
    db = new Database();
    } catch (ClassNotFoundException ex) {
    Logger.getLogger(PacketSniffer.class.getName()).lo g(Level.SEVERE, null, ex);
    }
    jpcap = JpcapCaptor.openDevice(devices[0], 65535, true, 20);

    // PacketAnalyzer analyzer = new PacketAnalyzer();

    while (!Thread.currentThread().isInterrupted()) {

    Packet packet = jpcap.getPacket();

    if (packet == null) {
    try {
    Thread.sleep(10);
    } catch (InterruptedException e) {
    Thread.currentThread().interrupt();
    continue;
    }
    } else {
    System.out.println("Packets Details" + packet.toString() );


    /*
    String s="gjdgURL:/192.142.564.15->bngjcgv";
    // String s="URL:cvnbckjhg*";

    String s1="";

    // String page = loadpage.loadPage();
    // Pattern pattern = Pattern.compile("<a.+href=\"(.+?)\"");
    Pattern pattern1 = Pattern.compile("/(.+?)->");
    Pattern pattern2 = Pattern.compile("URL.+: (.+?)\n");
    // Class.forName("com.mysql.jdbc.Driver");
    //Connection con;

    Matcher matcher = pattern1.matcher(s);
    int i=1;
    while (matcher.find()) {
    // System.out.println("hi"+s);

    s1=matcher.group(1);
    System.out.println("hi:"+s1);

    }

    */




    if (packet instanceof IPPacket) {
    IPPacket ip = (IPPacket) packet;
    }if (packet instanceof TCPPacket){
    tcp.analyze(packet);
    tcp.getValues();
    String result = cal.ReadRule(tcp.getValue());
    // System.out.println("result"+result);
    if(result.equals("normal")){}
    else{

    File f=new File("c:\\dataset1.arff");
    FileOutputStream fop=new FileOutputStream(f,true);
    if(f.exists()){

    fop.write((tcp.getAttribute()+result+"\n").getByte s());
    // fop.write("\n".getBytes());
    fop.flush();
    fop.close();
    System.out.println("The data has been written");
    }

    // filewriter = new FileWriter("c:\\dataset1.txt",true);
    System.out.println(tcp.getAttribute()+result);
    // filewriter.write(tcp.getAttribute()+result);

    String s=packet.toString();


    // String page = loadpage.loadPage();
    // Pattern pattern = Pattern.compile("<a.+href=\"(.+?)\"");
    Pattern pattern1 = Pattern.compile("/(.+?)->");
    // Pattern pattern2 = Pattern.compile("URL.+: (.+?)");
    // Class.forName("com.mysql.jdbc.Driver");
    //Connection con;

    Matcher matcher = pattern1.matcher(s);
    int i=1;
    while (matcher.find()) {
    s1=matcher.group(1);

    }

    db.executeUpdate1(result,s1);

    }
    System.out.println("result"+result+" fromT********"+s1);
    }if(packet instanceof UDPPacket){
    udp.analyze(packet);
    udp.getValues1();
    String result = cal.ReadRule(udp.getValue());

    if(result.equals("normal")){}
    else{
    File f=new File("c:\\dataset1.arff");
    FileOutputStream fop=new FileOutputStream(f,true);
    if(f.exists()){
    fop.write(
    (udp.getAttribute()+result+"\n").getBytes());
    // fop.write("\n".getBytes());
    String s2=packet.toString();


    Pattern pattern2 = Pattern.compile("/(.+?)->");

    Matcher matcher1 = pattern2.matcher(s2);
    int i=1;
    while (matcher1.find()) {
    s3=matcher1.group(1);

    }

    fop.flush();
    fop.close();
    System.out.println("The data has been written");
    }
    else{
    System.out.println("This file is not exist");
    }
    System.out.println(udp.getAttribute()+result);

    db.executeUpdate1(result,s3);
    }
    System.out.println("result"+result+"from(********* ****"+s3);
    }
    }
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    public static void main(String arg[]) throws SQLException{
    PacketSniffer packetsniffer = new PacketSniffer();
    packetsniffer.startCapture();
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: jpcap packet captor cant capture packet

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. 1 packet delay with inputstream
    By tobi06 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: October 27th, 2011, 04:53 AM
  2. [SOLVED] Basics With UDP Packet
    By servalsoft in forum Java Networking
    Replies: 0
    Last Post: October 13th, 2011, 12:47 PM
  3. Help with newtwork packet sniffer
    By f0xhound in forum Java Networking
    Replies: 3
    Last Post: September 5th, 2011, 02:29 PM
  4. jpcap ethernet packet lengh
    By proskopos in forum Java Networking
    Replies: 2
    Last Post: March 15th, 2011, 11:30 AM
  5. Replies: 6
    Last Post: October 23rd, 2009, 03:53 AM