2012-12-14 49 views
2

我有一个程序使用jpcap捕获网络ip地址。但我得到这个错误如何克服JpCap问题?

// 线程“主”的异常java.lang.UnsatisfiedLinkError:jpcap.JpcapCaptor.getDeviceList()[Ljpcap/NetworkInterface; 在jpcap.JpcapCaptor.getDeviceList(本机方法) 在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(); 

     } 
     } 

回答

0

正如Javadoc中说

Thrown if the Java Virtual Machine cannot find an appropriate native-language definition of a method declared native.

我猜想它找不到它的本地库。你有PATH环境变量中指定的jpcap.dll文件吗?

+0

上次我使用jpcap(大约5年前)它不能在x64窗口中工作。 – Behnil

+0

我将该Dll文件放在system32文件夹中。但没有任何工作 – ags

+0

你有什么系统操作系统?它是32b还是64b? – Behnil

1

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

如果使用Eclipse,请确保将已安装的JRE的设置定义为指向32位版本,并且您的java项目正在使用工作区默认设置。它应该自动地选择一切。