简体   繁体   中英

Programming with Java jpcap on Eclipse Indigo IDE on Windows 7 platform

I'm programming in Java and new to jpcap. I have installed Jpcap for Microsoft Windows. My PC runs on Windows 7 Platform. I have an Eclipse Indigo IDE. When i created a new Java Project using the Eclipse Indigo IDE, i created a class with a main method and i copied and pasted the code from the jpcap tutorial.

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);
    }
}

On the Java Code Editor for Eclipse Indigo IDE, i saw red lines marked for the NetworkInterface class,the NetworkInterface device, a objects and its attribute variables.

When i mouse over the red markers, i saw this error message that says :

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

When i ran the Java program,there was no compilation error thrown and the Java console was able to show the output correctly. Why is that so?? Is there any way to remove the red markers on the Java Editor whenever i call the jpcap library on the Eclipse Indigo IDE? Is it because i didn't install winpcap for windows?

I ran into the exact same problem, and it took me a while to figure out the solution. Hope this helps.

  1. You have to recognize that Jpcap is 32-bit and you're most likely running the 64-bit version of Eclipse on Windows 7. Make sure you're running the 32-bit Eclipse for this.

  2. Go to the Jpcap download section and put the files, jpcap-0.6.zip and JPcapSetup-0.6.exe in a folder. Unzip and execute them.

  3. Copy the Jpcap.dll file to the C:\\Windows\\System32 folder

  4. Start Eclipse, make a new project, make new package, make a new class, write your code.

  5. Right click on the project name --> Build Path --> Configure Build Path ... --> Java Build Path --> Add External JARs...

  6. Add the jpcap.jar file.

  7. Run your program.

Try it from NetBeans, and try to import the library manually, if you need to install it. jpcap.jar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM