使用jpcap 获得硬件信息 我的代码有错吗 我写的一个测试 但是没有结果阿

cprime 2009-05-11 10:36:37
我的编译调试环境是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 }


小弟在此请教了,麻烦各位了。
...全文
181 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
y384655321 2009-05-21
  • 打赏
  • 举报
回复
第二个程序
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
这样也可以,希望有所帮助,调式环境同上
y384655321 2009-05-21
  • 打赏
  • 举报
回复
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,希望有帮助
zhaodalong 2009-05-13
  • 打赏
  • 举报
回复
友情 up !
但是这个问题我真的不会!
cprime 2009-05-13
  • 打赏
  • 举报
回复
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());
}
}


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

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧