2012-12-14 72 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項目正在使用工作區默認設置。它應該自動地選擇一切。