我想尝试处理 Pcap4J 库,但我一开始就卡住了。我找到了现成的项目,通过 Maven 加载了所有必要的库。代码仍然没有运行,抛出异常:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'wpcap':
Не найден указанный модуль.
Не найден указанный модуль.
Не найден указанный модуль.
Can't obtain InputStream for win32-x86-64/wpcap.dll
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:302)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:455)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:397)
at com.sun.jna.Function.getFunction(Function.java:102)
at org.pcap4j.core.NativeMappings.<clinit>(NativeMappings.java:44)
at org.pcap4j.core.Pcaps.findAllDevs(Pcaps.java:56)
at org.pcap4j.util.NifSelector.selectNetworkInterface(NifSelector.java:34)
at Main.main(Main.java:16)
Suppressed: java.lang.UnsatisfiedLinkError: Не найден указанный модуль.
at com.sun.jna.Native.open(Native Method)
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:191)
... 7 more
Suppressed: java.lang.UnsatisfiedLinkError: Не найден указанный модуль.
at com.sun.jna.Native.open(Native Method)
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:204)
... 7 more
Suppressed: java.lang.UnsatisfiedLinkError: Не найден указанный модуль.
at com.sun.jna.Native.open(Native Method)
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:265)
... 7 more
Suppressed: java.io.IOException: Can't obtain InputStream for win32-x86-64/wpcap.dll
at com.sun.jna.Native.extractFromResourcePath(Native.java:1115)
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:276)
... 7 more
我做错了什么,他为什么抱怨?也许有人使用过这个库并且可以判断。
项目示例:
import com.sun.jna.NativeLibrary;
import org.pcap4j.core.PcapNetworkInterface;
import org.pcap4j.util.NifSelector;
import java.io.IOException;
public class Main {
public static void main(String[] args)
{
// The class that will store the network device
// we want to use for capturing.
PcapNetworkInterface device = null;
// Pcap4j comes with a convenient method for listing
// and choosing a network interface from the terminal
try {
// List the network devices available with a prompt
device = new NifSelector().selectNetworkInterface();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("You chose: " + device);
}
}
通过安装 WinPcap winpcap.org/install/default.htm 解决了问题