从java获取接口NAME
我的操作系统是 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定已正确更改网卡名称,请检查以下链接 CentOS网卡名称更改
Are you sure you have changed the NIC name properly, please check the following link CentOS NIC name change