如何克服JpCap问题?

时间:2012-12-14 14:00:45

标签: java exception error-handling jpcap

我有一个使用jpcap捕获网络IP地址的程序。但是我收到了这个错误

// 线程“main”中的异常java.lang.UnsatisfiedLinkError:jpcap.JpcapCaptor.getDeviceList()[Ljpcap / NetworkInterface;         at jpcap.JpcapCaptor.getDeviceList(Native Method)         在example.Main.main(Main.java:25)//

我的节目

        package example;

        /**
         *
      * @author Administrator
      */
      import java.net.Inet4Address;
    import java.net.InetAddress;
   import java.util.Arrays;
  import java.io.IOException;
  import java.io.*;
  import java.util.Scanner;
 import jpcap.*;
 import jpcap.packet.*;

 public class Main{
public static void main(String[] args) throws IOException{

  //Obtain the list of network interfaces
 NetworkInterface[] devices = JpcapCaptor.getDeviceList();

//for each network interface
 for (int i = 0; i < devices.length; i++) {/ /print out its name and description
System.out.println(i+": "+devices[i].name + "(" + devices[i].description+")");

 //print out its datalink name and description
System.out.println(" datalink: "+devices[i].datalink_name + "(" +   devices[i].datalink_description+")");

 //print out its MAC address
   System.out.print(" MAC address:");
   for (byte b : devices[i].mac_address)
  System.out.print(Integer.toHexString(b&0xff) + ":");
   System.out.println();

  //print out its IP address, subnet mask and broadcast address
    for (NetworkInterfaceAddress a : devices[i].addresses)
   System.out.println(" address:"+a.address + " " + a.subnet + " "+ a.broadcast);
   }

   //NetworkInterface[] devices = JpcapCaptor.getDeviceList();
   int index =1; // set index of the interface that you want to open.

    //Open an interface with openDevice(NetworkInterface intrface, int snaplen,           boolean promics, int to_ms)
    final JpcapCaptor captor=JpcapCaptor.openDevice(devices[index], 65535, false, 20);









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

  //call processPacket() to let Jpcap call PacketPrinter.receivePacket() for every packet capture.
   //captor.processPacket(10,new PacketPrinter());
  //System.out.println(packet);
//captor.close();

      }
      }

2 个答案:

答案 0 :(得分:1)

首先,您需要使用Java 32位版本。安装它然后将jpcap dll复制到bin文件夹中。并将jpcap jar复制到lib / ext文件夹中。

如果使用Eclipse,请确保将已安装的JRE的设置定义为指向32位版本,并且您的java项目使用工作空间默认值。它应该自动选择所有内容。

答案 1 :(得分:0)

正如javadoc所说

  

如果Java虚拟机无法找到声明为native的方法的适当本机语言定义,则抛出该文件。

我猜它找不到它的原生库。你有一个由PATH环境变量指定的jpcap.dll文件吗?