java - 查找以太网连接的网络适配器名称

标签 java windows networking

我需要找到用于连接互联网的以太网适配器的适配器名称和默认网关。

我可以通过 netstat -rn 获取网关但我的适配器名称有问题。

我正在使用 java 并运行 ipconfig Windows 系统的命令并解析结果。它以这种格式返回网络适配器名称

Ethernet adapter Local Area Connection:

   Connection-specific DNS Suffix  . : customer.service.provider.lan
   Link-local IPv6 Address . . . . . : fb80::7d2b:98aa:506:685%10
   IPv4 Address. . . . . . . . . . . : 10.65.2.21
   Subnet Mask . . . . . . . . . . . : 255.255.192.0
   Default Gateway . . . . . . . . . : 10.65.0.1

我可以匹配默认网关,并喜欢为其解析字符串“本地连接”。在英语语言环境中,我可以查找单词“适配器”并解析名称直到“:”。问题是在区域设置与英语不同的计算机上,“适配器”被称为其他名称。如何可靠地获取网络适配器名称?

最佳答案

看看这个 tutorial :列出网络接口(interface)地址 并使用 getDisplayName() 代替 getName()。请参阅此处获取网关:How can I determine the IP of my router/gateway in Java?

关于java - 查找以太网连接的网络适配器名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8626821/

相关文章:

java - 如何在 Struts 2 中实现分页

java - 如何在 Java 程序中获取 "ribbon"UI 组件,例如在 Office 2007 中?

java.lang.NoClassDefFoundError : javafxports. android.FXDalvikEntity$2

windows - 查看给定计算机上的事件远程桌面连接

azure - 无法使用虚拟 IP 从我的 Azure 网站连接到 Azure 云服务?

java - 使用 gen_tcp :send doesn't get sent until the socket is closed 的消息

c - JNA 简单函数调用适用于 Linux (x64),但不适用于 Windows (x86)

windows - 尝试使用 win xp cmd 与设备通信

swift - 在 Playground 或项目外快速联网?

java - 什么是主机动态发现?那么它在Java RMI中是如何应用的呢?