简体   繁体   中英

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. Unfortunately, some classes like NetworkInterface can't be serialized (is that the right word?) to xml by a XMLEncoder . Thus, I thought about simply writing a string that identifies the network interface and get the NetworkInterface instance by using NetworkInterface.getByName() method.

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. If you need something like this, have a look at MAC addresses .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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