2012-04-12 38 views
2

我使用Java进行编程,并且使用jpcap。 我已经为Microsoft Windows安装了Jpcap。我的电脑在Windows 7平台上运行。我有一个Eclipse Indigo IDE。当我使用Eclipse Indigo IDE创建一个新的Java项目时,我使用主要方法创建了一个类,并且我复制并粘贴了jpcap教程中的代码。在Windows 7平台上在Eclipse Indigo IDE上使用Java jpcap进行编程

package PacketCapturing; 

import jpcap.*; 
import jpcap.packet.*; 

public class NetworkInterfaceList { 

public static void main(String args[]){ 
    //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); 
    } 
} 

在Java代码编辑器的Eclipse IDE靛蓝,我看到标记为NetworkInterface类的NetworkInterface的设备,对象和它的属性变量红线。

当我鼠标的红色标记,我看到了,说此错误消息:

Access restriction: The type NetworkInterface is not accessible due to restriction on required library C:\Windows\Sun\Java\lib\ext\jpcap.jar 

,当我跑Java程序,没有编译错误时,抛出和Java控制台能够显示输出正确。为什么??每当我调用Eclipse Indigo IDE上的jpcap库时,是否有任何方法可以删除Java编辑器上的红色标记?是否因为我没有安装windows的winpcap?

回答

-1

从NetBeans中尝试它,并尝试手动导入库(如果需要安装它)。 jpcap.jar

1

我遇到了完全相同的问题,并花了我一段时间来找出解决方案。希望这可以帮助。

  1. 你必须认识到,JPCAP是32位的,你就极有可能在运行Eclipse的在Windows 7 64位版本,请确保您运行的是32位的Eclipse这一点。

  2. 转到Jpcap下载部分,并将文件jpcap-0.6.zip和JPcapSetup-0.6.exe放到一个文件夹中。解压并执行它们。

  3. 复制Jpcap.dll文件到C:\ windows \ system32目录

  4. 启动Eclipse,创建一个新的项目,使新的包装,使一个新的类,编写代码。

  5. 在项目名称上点击右键 - >构建路径 - >配置构建路径 - > Java构建路径 - >添加外部JAR ...

  6. 添加jpcap.jar文件。

  7. 运行您的程序。

相关问题