我的编译调试环境是debian lenny 5.0 下:jpcap的开发环境以搭建好。源码如下,一个测试:
  1 import jpcap.*;
  2 
  3 public class Devices {
  4         public static void main(String []args) {
  5                 NetworkInterface []devices = JpcapCaptor.getDeviceList();
  6 
  7                 try{
  8                         for(int i=0; i<devices.length; i++) {
  9                                 System.out.println(devices[i].name); //这里的本意是得到网络界面的名字但什么都没有
 10                         }
 11                 } catch(ArrayIndexOutOfBoundsException e) {
 12                         System.out.println("this array is out");
 13                 }
 14         }
 15 }
小弟在此请教了,麻烦各位了。

解决方案 »

  1.   

    2天了csdn就没一个这方面的人吗?????????????
    下面这个代码也是没有什么输出.有谁在windows下配置了jpcap 帮我测试一下吗,无论有什么输出都贴上来。我
    在debian下什么都没有。import jpcap.*;
    import jpcap.packet.*;public class JpcapTip implements PacketReceiver{
     public void    receivePacket(Packet packet) {
       System.out.println(packet);
     } public static void main(String[] args) throws java.io.IOException{
            NetworkInterface [] devices = JpcapCaptor.getDeviceList();
            JpcapCaptor jpcap = null;
            for (int i = 0; i < devices.length; i++) {
                    System.out.println(devices[i]);
            }
            NetworkInterface deviceName = devices[0];
            jpcap.openDevice(deviceName, 1028, false, 1); 
            jpcap.loopPacket(-1, new JpcapTip());
     }

    没人回帖阿真郁闷阿!!!!!!!!!!!!!!!!!!!!!!!!!!
      

  2.   

    import jpcap.*; 
    public class dun {        public static void main(String []args) { 
              String[] lists=Jpcap.getDeviceDescription();              try{ 
                           for(int i=0; i <lists.length; i++) { 
                                   System.out.println(lists[i]); //这里的本意是得到网络界面的名字但什么都没有 
                            } 
                    } catch(ArrayIndexOutOfBoundsException e) { 
                            System.out.println("this array is out"); 
                   } 
            } 

    Adapter for generic dialup and VPN capture
    MS Tunnel Interface Driver
    Realtek RTL8169/8110 Family Gigabit Ethernet NIC                                
    这样可以,看了下doc文档,Jpcap.getDeviceDescription();返回的是string,我用的是myeclipse6.5,希望有帮助
      

  3.   

    第二个程序
    package netcap;
    import jpcap.*;
    public class dun implements PacketReceiver, JpcapHandler{ 

    public static void main(String[] args) throws java.io.IOException{ 
     String[] lists=Jpcap.getDeviceDescription(); 
            JpcapCaptor jpcap = null; 
            for (int i = 0; i < lists.length; i++) { 
                    System.out.println(lists[i]); 
            } 
            //NetworkInterface deviceName = lists[0]; 
            Jpcap jpcap1=Jpcap.openDevice(Jpcap.getDeviceList()[0],1000,true,20);  //true,the inferface becomes promiscuous mode(混杂模式)
     jpcap1.loopPacket( -1, new dun());
    } @Override
    public void receivePacket(jpcap.packet.Packet arg0) {
    // TODO Auto-generated method stub
     System.out.println(arg0);
    } @Override
    public void handlePacket(Packet arg0) {
    // TODO Auto-generated method stub


    } Adapter for generic dialup and VPN capture
    MS Tunnel Interface Driver
    Realtek RTL8169/8110 Family Gigabit Ethernet NIC  
    这样也可以,希望有所帮助,调式环境同上