简体   繁体   English

Java:NetworkInterface.getName()是唯一的标识符,该标识符不会随时间变化吗?

[英]Java: Is NetworkInterface.getName() a unique identifier that will not change over time?

I'm storing some network data in an xml file using XMLEncode , since it is really convenient. 我使用XMLEncode将一些网络数据存储在xml文件中,因为它确实很方便。 Unfortunately, some classes like NetworkInterface can't be serialized (is that the right word?) to xml by a XMLEncoder . 不幸的是,某些类(如NetworkInterface )无法通过XMLEncoder序列化(对吗?)。 Thus, I thought about simply writing a string that identifies the network interface and get the NetworkInterface instance by using NetworkInterface.getByName() method. 因此,我想到了简单地编写一个字符串来标识网络接口,并使用NetworkInterface.getByName()方法获取NetworkInterface实例。

My question: is this name ensured to be unique and not to be changed over time (assuming that no changes are made in the network configuration of the machine)? 我的问题:是否确保此名称唯一且不会随时间更改(假设计算机的网络配置未更改)? Ie, is this name on one machine always going to identify the same network interface? 即,一台机器上的这个名称是否总是会标识相同的网络接口?

The name of the NetworkInterface is unique on the same machine (your assumption: no changes in the network configuration), but the name is not at all globally unique. NetworkInterface的名称在同一台计算机上是唯一的(您的假设:网络配置没有变化),但是该名称在全局上根本不是唯一的。 If you need something like this, have a look at MAC addresses . 如果您需要类似的内容,请查看MAC地址

However, the name of the NetworkInterface identifies a virtual Interface (on Linux systems for example eth0 for Ethernet, ath0 for Wireless) and at the moment I don't understand why you would store the interface name, since the IP address assigned to this Interface, could change easily. 但是,NetworkInterface的名称标识了一个虚拟接口(在Linux系统上,例如eth0表示以太网,ath0表示无线),目前我不知道为什么要存储接口名称,因为分配给该接口的IP地址,可以轻松更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM