谁能解释为什么 Java GetNetworkInterfaces 在 Windows 7 上返回这么多接口

发布于 2024-11-06 05:44:05 字数 5979 浏览 3 评论 0原文

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

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

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

  • Intel(R) 82567LM-3 千兆位网络连接
  • Intel(R) 82567LM-3 千兆位网络连接-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 1
Name: lo
InetAddress: /0:0:0:0:0:0:0:1
InetAddress: /127.0.0.1
Up? true
Loopback? true
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: []
MTU: -1

Display name: WAN Miniport (SSTP)
Name: net0
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: WAN Miniport (IKEv2)
Name: net1
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: WAN Miniport (L2TP)
Name: net2
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: WAN Miniport (PPTP)
Name: net3
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: WAN Miniport (PPPOE)
Name: ppp0
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: WAN Miniport (IPv6)
Name: eth0
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: WAN Miniport (Network Monitor)
Name: eth1
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: WAN Miniport (IP)
Name: eth2
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: RAS Async Adapter
Name: ppp1
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: Intel(R) 82567LM-3 Gigabit Network Connection
Name: eth3
InetAddress: /fe80:0:0:0:b1b1:7531:17b1:bf26%11
InetAddress: /172.24.9.148
Up? true
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: [120, 43, -53, 125, -80, 74]
MTU: 1500

Display name: Microsoft ISATAP Adapter
Name: net4
Up? false
Loopback? false
PointToPoint? true
Supports multicast? false
Virtual? false
Hardware address: [0, 0, 0, 0, 0, 0, 0, -32]
MTU: 1280

Display name: Teredo Tunneling Pseudo-Interface
Name: net5
InetAddress: /fe80:0:0:0:e0:0:0:0%13
Up? false
Loopback? false
PointToPoint? true
Supports multicast? false
Virtual? false
Hardware address: [0, 0, 0, 0, 0, 0, 0, -32]
MTU: 1280

Display name: Microsoft ISATAP Adapter #2
Name: net6
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: Intel(R) 82567LM-3 Gigabit Network Connection-QoS Packet Scheduler-0000
Name: eth4
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: Intel(R) 82567LM-3 Gigabit Network Connection-WFP LightWeight Filter-0000
Name: eth5
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: WAN Miniport (Network Monitor)-QoS Packet Scheduler-0000
Name: eth6
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: WAN Miniport (IP)-QoS Packet Scheduler-0000
Name: eth7
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: WAN Miniport (IPv6)-QoS Packet Scheduler-0000
Name: eth8
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

I have been using NetworkInterface.getNetworkInterfaces()
to query the Network Interfaces on my machine. Essentially I am trying to find Network Interface Cards. These are usually called something like eth0, eth1 etc..

Its been working great on win xp and even vista with a litle filtering.

I just noticed in certain configurations of windows 7 I get a large number of listed network adapters. Way more than on xp and vista. I have only one card configured but seem to get three different network interfaces

  • Intel(R) 82567LM-3 Gigabit Network Connection
  • Intel(R) 82567LM-3 Gigabit Network Connection-QoS Packet Scheduler-0000
  • Intel(R) 82567LM-3 Gigabit Network Connection-WFP LightWeight Filter-0000

Why 3 different points for essentially the same thing.

I also have six entries for something called WAN MINIPORT.
(See below for output)

I can filter out these but of course there is a performance cost in going through so much crap. Does anyone know why these entries are created and how to minimise them ?

As an example on my system I wrote code like this

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

    }

}

On windows 7 output is

Display name: Software Loopback Interface 1
Name: lo
InetAddress: /0:0:0:0:0:0:0:1
InetAddress: /127.0.0.1
Up? true
Loopback? true
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: []
MTU: -1

Display name: WAN Miniport (SSTP)
Name: net0
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: WAN Miniport (IKEv2)
Name: net1
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: WAN Miniport (L2TP)
Name: net2
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: WAN Miniport (PPTP)
Name: net3
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: WAN Miniport (PPPOE)
Name: ppp0
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: WAN Miniport (IPv6)
Name: eth0
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: WAN Miniport (Network Monitor)
Name: eth1
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: WAN Miniport (IP)
Name: eth2
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: RAS Async Adapter
Name: ppp1
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: Intel(R) 82567LM-3 Gigabit Network Connection
Name: eth3
InetAddress: /fe80:0:0:0:b1b1:7531:17b1:bf26%11
InetAddress: /172.24.9.148
Up? true
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: [120, 43, -53, 125, -80, 74]
MTU: 1500

Display name: Microsoft ISATAP Adapter
Name: net4
Up? false
Loopback? false
PointToPoint? true
Supports multicast? false
Virtual? false
Hardware address: [0, 0, 0, 0, 0, 0, 0, -32]
MTU: 1280

Display name: Teredo Tunneling Pseudo-Interface
Name: net5
InetAddress: /fe80:0:0:0:e0:0:0:0%13
Up? false
Loopback? false
PointToPoint? true
Supports multicast? false
Virtual? false
Hardware address: [0, 0, 0, 0, 0, 0, 0, -32]
MTU: 1280

Display name: Microsoft ISATAP Adapter #2
Name: net6
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: Intel(R) 82567LM-3 Gigabit Network Connection-QoS Packet Scheduler-0000
Name: eth4
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: Intel(R) 82567LM-3 Gigabit Network Connection-WFP LightWeight Filter-0000
Name: eth5
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: WAN Miniport (Network Monitor)-QoS Packet Scheduler-0000
Name: eth6
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: WAN Miniport (IP)-QoS Packet Scheduler-0000
Name: eth7
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

Display name: WAN Miniport (IPv6)-QoS Packet Scheduler-0000
Name: eth8
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: null
MTU: -1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴梦一场 2024-11-13 05:44:05

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

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

Windows defines many interfaces for internal use. Java just returns what the OS tell gives it, none of these are added by Java.

You should be able to find entries for all these devices in the Windows Registry.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文