从java获取接口NAME

发布于 2024-12-24 17:13:27 字数 665 浏览 6 评论 0原文

我的操作系统是 CentOS 6。在我的 /etc/sysconfig/network-scripts/ifcfg-eth0 文件中,我已将网络接口 "NAME" 指定为 "foo" (让我们假设)。

NAME=foo

我希望能够从 java 获取该接口 "NAME"。我尝试了以下操作,但没有结果:


     for (Enumeration nis = NetworkInterface.getNetworkInterfaces(); nis.hasMoreElements();) {
         NetworkInterface ni = nis.nextElement();
     System.out.println(ni.getDisplayName() + " " + ni.getName());
     }

它显示相同的内容:

eth0 eth0

谁能告诉我是否可以获得网络属性 NAME 的值接口,在java中?

谢谢。

注意:当指定 NAME=foo 时,屏幕右上角网络面板中该接口的名称为 foo

My OS is CentOS 6. In my /etc/sysconfig/network-scripts/ifcfg-eth0 file, I have specified the network interface "NAME" to "foo" (let's suppose).

NAME=foo

I want to be able to get that interface "NAME" from java. I tried the following, without a result:


     for (Enumeration nis = NetworkInterface.getNetworkInterfaces(); nis.hasMoreElements();) {
         NetworkInterface ni = nis.nextElement();
     System.out.println(ni.getDisplayName() + " " + ni.getName());
     }

It displays the same thing:

eth0 eth0

Can anybody tell me if it is possible to get the value of NAME, property of a network interface, in java?

Thanks.

NOTE: When specify NAME=foo, then the name of that interface in the network panel placed on the up right corner of the screen is foo.

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

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

发布评论

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

评论(1

迷路的信 2024-12-31 17:13:27

您确定已正确更改网卡名称,请检查以下链接 CentOS网卡名称更改

Are you sure you have changed the NIC name properly, please check the following link CentOS NIC name change

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