gpt4 book ai didi

java - 如何克服 JpCap 问题?

转载 作者:行者123 更新时间:2023-11-30 11:37:51 24 4
gpt4 key购买 nike

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

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

}
}

最佳答案

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

如果使用 Eclipse,请确保将安装的 JRE 的设置定义为指向 32 位版本,并且您的 Java 项目使用默认工作区。然后它应该会自动拾取所有内容。

关于java - 如何克服 JpCap 问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13880118/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com