如何克服JpCap问题



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

//线程"main"java.lang.UnsatisfiedLinkError中的异常:jpcap。JpcapCaptor.getDeviceList()[Ljpcap/NetworkInterface; 在JPCAP。JpcapCaptor.getDeviceList(Native Method) 例如。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();
      }
      }

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

如果使用 Eclipse,请确保将已安装的 JRE 的设置定义为指向 32 位版本,并且您的 Java 项目使用的是缺省值。然后它应该自动拾取所有东西。

正如javadoc所说

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

我猜它找不到它的原生库。您是否在 PATH 环境变量指定的文件之一中提供了 jpcap.dll 文件?

相关内容

  • 没有找到相关文章

最新更新