gpt4 book ai didi

java - java获取windows网卡 "Media State"?

转载 作者:可可西里 更新时间:2023-11-01 09:34:16 24 4
gpt4 key购买 nike

如何在 Windows 中获取网络适配器的媒体状态?我搜索了一下,它看起来不像 java.net.NetworkInterface 类提供这种能力,这是有道理的,因为它似乎是一个甚至不适用于所有适配器的 Windows 概念。当我运行 ipconfig 时,我得到如下内容:

Windows IP Configuration


Wireless LAN adapter Wireless Network Connection 5:

Connection-specific DNS Suffix . : BlahBlah.Blah
IPv4 Address. . . . . . . . . . . : 192.168.113.44
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.113.1

Ethernet adapter Local Area Connection 8:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . : BlahBlah.Blah

如果我使用在 Can anyone explain why Java GetNetworkInterfaces returns so many interfaces on 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: Intel(R) 82579LM Gigabit Network Connection #2
Name: eth13
InetAddress: /172.16.4.29
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: [60, -105, 14, -77, -123, 110]
MTU: 1500

Display name: Intel(R) Centrino(R) Advanced-N 6205 #3
Name: net11
InetAddress: /192.168.113.44
Up? false
Loopback? false
PointToPoint? false
Supports multicast? true
Virtual? false
Hardware address: [60, -105, 14, -77, -123, 110]
MTU: 1500

关于如何确定以太网适配器是否“媒体断开连接”的想法?

最佳答案

您可以引用以下代码片段。基本上 !networkInterface.isUp() 应该可以为您解决问题。

List<NetworkInterface> nic = new ArrayList<>();
interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface networkInterface = interfaces.nextElement();
if (!networkInterface.isUp())
continue;
nic.add(networkinterface);
}

关于java - java获取windows网卡 "Media State"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19410525/

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