首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何克服JpCap问题?

如何克服JpCap问题?
EN

Stack Overflow用户
提问于 2012-12-14 22:00:45
回答 2查看 3.1K关注 0票数 2

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

//线程"main“中出现异常: jpcap.JpcapCaptor.getDeviceList()[Ljpcap/NetworkInterface;at jpcap.JpcapCaptor.getDeviceList(本机方法) at example.Main.main(Main.java:25)//

我的程序

代码语言:javascript
复制
        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();

      }
      }
EN

回答 2

Stack Overflow用户

发布于 2013-01-15 12:54:07

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

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

票数 1
EN

Stack Overflow用户

发布于 2012-12-14 22:28:42

正如javadoc所说的那样

如果Java Virtual Machine找不到声明为本机的方法的适当本机语言定义,则抛出

我猜它找不到自己的本地库。在PATH环境变量指定的其中一个中是否有可用的jpcap.dll文件?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13880118

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档