gpt4 book ai didi

java - 谁能解释为什么 Java GetNetworkInterfaces 在 Windows 7 上返回这么多接口(interface)

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:01:37 25 4
gpt4 key购买 nike

我一直在使用 NetworkInterface.getNetworkInterfaces()查询我机器上的网络接口(interface)。本质上,我正在尝试寻找网络接口(interface)卡。这些通常称为 eth0、eth1 等。

它在 win xp 甚至 vista 上运行良好,只需一点过滤。

我刚刚注意到在 Windows 7 的某些配置中我得到了大量列出的网络适配器。远远超过 xp 和 vista。我只配置了一张卡,但似乎有三个不同的网络接口(interface)

  • Intel(R) 82567LM-3 千兆网络连接
  • Intel(R) 82567LM-3 Gigabit Network Connection-QoS Packet Scheduler-0000
  • Intel(R) 82567LM-3 千兆网络连接-WFP LightWeight Filter-0000

为什么本质上相同的东西有 3 个不同的点。

我还有六个名为 WAN MINIPORT 的条目。(见下面的输出)

我可以过滤掉这些,但当然,经历这么多废话会有性能成本。有谁知道为什么要创建这些条目以及如何将它们最小化?

作为我的系统的例子,我写了这样的代码

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;

import static java.lang.System.out;


public class ListNetsEx {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Enumeration<NetworkInterface> nets;
try {
nets = NetworkInterface.getNetworkInterfaces();
for (NetworkInterface netint : Collections.list(nets))
displayInterfaceInformation(netint);
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

private static void displayInterfaceInformation(NetworkInterface netint) throws SocketException {
// TODO Auto-generated method stub
out.printf("Display name: %s\n", netint.getDisplayName());
out.printf("Name: %s\n", netint.getName());
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();

for (InetAddress inetAddress : Collections.list(inetAddresses)) {
out.printf("InetAddress: %s\n", inetAddress);
}

out.printf("Up? %s\n", netint.isUp());
out.printf("Loopback? %s\n", netint.isLoopback());
out.printf("PointToPoint? %s\n", netint.isPointToPoint());
out.printf("Supports multicast? %s\n", netint.supportsMulticast());
out.printf("Virtual? %s\n", netint.isVirtual());
out.printf("Hardware address: %s\n",
Arrays.toString(netint.getHardwareAddress()));
out.printf("MTU: %s\n", netint.getMTU());

out.printf("\n");

}

}

在 Windows 7 上输出是

Display name: Software Loopback Interface 1Name: loInetAddress: /0:0:0:0:0:0:0:1InetAddress: /127.0.0.1Up? trueLoopback? truePointToPoint? falseSupports multicast? trueVirtual? falseHardware address: []MTU: -1Display name: WAN Miniport (SSTP)Name: net0Up? falseLoopback? falsePointToPoint? falseSupports multicast? trueVirtual? falseHardware address: nullMTU: -1Display name: WAN Miniport (IKEv2)Name: net1Up? falseLoopback? falsePointToPoint? falseSupports multicast? trueVirtual? falseHardware address: nullMTU: -1Display name: WAN Miniport (L2TP)Name: net2Up? falseLoopback? falsePointToPoint? falseSupports multicast? trueVirtual? falseHardware address: nullMTU: -1Display name: WAN Miniport (PPTP)Name: net3Up? falseLoopback? falsePointToPoint? falseSupports multicast? trueVirtual? falseHardware address: nullMTU: -1Display name: WAN Miniport (PPPOE)Name: ppp0Up? falseLoopback? falsePointToPoint? falseSupports multicast? trueVirtual? falseHardware address: nullMTU: -1Display name: WAN Miniport (IPv6)Name: eth0Up? falseLoopback? falsePointToPoint? falseSupports multicast? trueVirtual? falseHardware address: nullMTU: -1Display name: WAN Miniport (Network Monitor)Name: eth1Up? falseLoopback? falsePointToPoint? falseSupports multicast? trueVirtual? falseHardware address: nullMTU: -1Display name: WAN Miniport (IP)Name: eth2Up? falseLoopback? falsePointToPoint? falseSupports multicast? trueVirtual? falseHardware address: nullMTU: -1Display name: RAS Async AdapterName: ppp1Up? falseLoopback? falsePointToPoint? falseSupports multicast? trueVirtual? falseHardware address: nullMTU: -1Display name: Intel(R) 82567LM-3 Gigabit Network ConnectionName: eth3InetAddress: /fe80:0:0:0:b1b1:7531:17b1:bf26%11InetAddress: /172.24.9.148Up? trueLoopback? falsePointToPoint? falseSupports multicast? trueVirtual? falseHardware address: [120, 43, -53, 125, -80, 74]MTU: 1500Display name: Microsoft ISATAP AdapterName: net4Up? falseLoopback? falsePointToPoint? trueSupports multicast? falseVirtual? falseHardware address: [0, 0, 0, 0, 0, 0, 0, -32]MTU: 1280Display name: Teredo Tunneling Pseudo-InterfaceName: net5InetAddress: /fe80:0:0:0:e0:0:0:0%13Up? falseLoopback? falsePointToPoint? trueSupports multicast? falseVirtual? falseHardware address: [0, 0, 0, 0, 0, 0, 0, -32]MTU: 1280Display name: Microsoft ISATAP Adapter #2Name: net6Up? falseLoopback? falsePointToPoint? falseSupports multicast? trueVirtual? falseHardware address: nullMTU: -1Display name: Intel(R) 82567LM-3 Gigabit Network Connection-QoS Packet Scheduler-0000Name: eth4Up? falseLoopback? falsePointToPoint? falseSupports multicast? trueVirtual? falseHardware address: nullMTU: -1Display name: Intel(R) 82567LM-3 Gigabit Network Connection-WFP LightWeight Filter-0000Name: eth5Up? falseLoopback? falsePointToPoint? falseSupports multicast? trueVirtual? falseHardware address: nullMTU: -1Display name: WAN Miniport (Network Monitor)-QoS Packet Scheduler-0000Name: eth6Up? falseLoopback? falsePointToPoint? falseSupports multicast? trueVirtual? falseHardware address: nullMTU: -1Display name: WAN Miniport (IP)-QoS Packet Scheduler-0000Name: eth7Up? falseLoopback? falsePointToPoint? falseSupports multicast? trueVirtual? falseHardware address: nullMTU: -1Display name: WAN Miniport (IPv6)-QoS Packet Scheduler-0000Name: eth8Up? falseLoopback? falsePointToPoint? falseSupports multicast? trueVirtual? falseHardware address: nullMTU: -1

最佳答案

Windows 定义了许多供内部使用的接口(interface)。 Java 只返回操作系统告诉它的内容,这些都不是 Java 添加的。

您应该能够在 Windows 注册表中找到所有这些设备的条目。

关于java - 谁能解释为什么 Java GetNetworkInterfaces 在 Windows 7 上返回这么多接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5953460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com