【问题标题】:Java get network connection listJava获取网络连接列表
【发布时间】:2017-07-12 10:08:27
【问题描述】:

我正在尝试使用 Java 获取 Windows 平台中的网络连接列表。我可以使用以下代码获取网络适配器

            Enumeration<NetworkInterface> interfaceList = NetworkInterface.getNetworkInterfaces();
        ArrayList<NetworkInterface> interfaces = new ArrayList<>(Collections.list(interfaceList));     

        for (NetworkInterface aInterface : interfaces) {
            if (aInterface.isLoopback() ||
                aInterface.isVirtual())
                continue;
            System.out.println(aInterface.getName() + ": " + aInterface.isUp());
        }

但这不是我想要的。这给了我一个很长的网络接口列表。在 Windows 中,当您转到“网络连接”窗口时,如果您有适配器,您可能会获得一个无线连接、一个网络连接和一个蓝牙。这是我想用 Java 检索的列表。

谢谢。

【问题讨论】:

    标签: java windows networking


    【解决方案1】:

    ! aInterface.isUp() 添加到条件中。 这会将列表减少为仅活动接口。

    【讨论】:

      猜你喜欢
      • 2021-06-15
      • 2011-03-21
      • 1970-01-01
      • 2022-07-16
      • 2012-10-15
      • 1970-01-01
      • 1970-01-01
      • 2011-06-24
      • 1970-01-01
      相关资源
      最近更新 更多