论坛首页 入门技术论坛

奇怪的结果!

浏览 1765 次
该帖已经被评为新手帖
作者 正文
   发表时间:2007-12-04  
package com.shoru.tom;

import java.net.NetworkInterface;
import java.net.SocketException;
import java.security.NoSuchAlgorithmException;
import java.util.Enumeration;

public class Test {
public static void main(String[] args) throws SocketException,
NoSuchAlgorithmException {
Enumeration<NetworkInterface> interfaces = null;
interfaces = NetworkInterface.getNetworkInterfaces();

while (interfaces.hasMoreElements()) {
System.out.println(interfaces.nextElement().isLoopback());
}

}
}
这种方法监测出我有三个EthernetAdapter,第一张是lo,回环为true,但是用jpcap的包监测得出三个都不是回环的!奇怪了,jpcap的代码如下:
package com.shoru.tom;

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

public class TestJpcap {
public static void main(String[] args) {
NetworkInterface[] devices = JpcapCaptor.getDeviceList();
for (int i = 0; i < devices.length; i++) {
if (!devices[i].loopback) {
System.out.println(devices[i].description);
System.out.println(devices[i].loopback);
}
}
}
}
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics