utilize NetworkInterface Get server MAC address    A lot of times , We need to get the server hardware information ( such as MAC address ), There are several common ways :
*   Using command line program to get hard disk information , And then through the Runtime.getRuntime().exec Get output stream , Then through string analysis MAC address
* Compiling local programs , And then through the JNI call    The above two methods need to distinguish different operating system platforms , Separate coding , It's troublesome , such as
*  windows The platform needs to be used iptables /all command
* linux The platform needs to be used ifconfig command     
  This paper introduces a general cross platform operation mode , That's it JDK Self contained NetworkInterface Interface , The interface is in the JDK1.4 It's already there , But it has less functions ,JDK1.6 Since then, many new functions have been added , Pretty good .
       Specific functions you can refer to API file , Here's how to get the server MAC address , The code is as follows , There are notes , Not much . // Get all network card's MAC address public
static List<String> getAllMac() { List<String> list = new ArrayList<String>();
try { Enumeration<NetworkInterface> e =
NetworkInterface.getNetworkInterfaces();// Returns an enumerated instance of all network interfaces while
(e.hasMoreElements()) { NetworkInterface network = e.nextElement();// Get current network interface
if (network != null) { if (network.getHardwareAddress() != null) { // get MAC address
// The result is a byte array , Each item is a byte, We need to pass parseByte Method to a common hexadecimal representation byte[] addres =
network.getHardwareAddress(); StringBuffer sb = new StringBuffer(); if (addres
!= null && addres.length > 1) {
parseByte(addres[4])).append(":").append( parseByte(addres[5]));
list.add(sb.toString()); } } } else { System.out.println(" obtain MAC Address exception "); } } }
catch (SocketException e) { e.printStackTrace(); } return list; } // Format binary
private static String parseByte(byte b) { int intValue = 0; if (b >= 0) {
intValue = b; } else { intValue = 256 + b; } return
Integer.toHexString(intValue); }  then , We use the following test code , Take a look at the test results List<String> list =
getAllMac(); for (String mac : list) { System.out.println(mac); }  The output results are as follows :
0:18:8b:cc:xx:e3 0:0:0:0:0:0:0:e0 0:50:xx:c0:0:1 0:50:xx:c0:0:8 
You found out ,"0:18:8b:cc:xx:e3", only one 0, It looks very awkward , We might as well revise it parseByte method , as follows : private static
String parseByte(byte b) { String s = "00"+Integer.toHexString(byte0); return
s.substring(s.length() - 2); }  The output changes : 00:18:8b:cc:xx:e3 00:00:00:00:00:e0
00:50:xx:c0:00:01 00:50:xx:c0:00:08  That makes it look much more comfortable , Is that so? ?
in addition ,NetworkInterface The interface also provides the following methods , You can refer to it .
* String displayName() Gets the display name of the network interface
* int getMTU() Returns the maximum transport unit for this interface (Maximum Transmission Unit,MTU)
* String getName() Gets the name of this network interface
* boolean isLoopback() Returns whether this network interface is a loopback interface
* boolean isPointToPoint() Returns whether this network interface is a point-to-point interface
* boolean isUp() Returns whether the network interface is turned on and running
* boolean isVirtual() Returns whether this interface is a virtual interface

©2019-2020 Toolsou All rights reserved,
Final review of database : Summary of comprehensive application questions use Python Make simple games Laplance operator ( Second derivative ) Convert hard disk to GPT Partition format Python Implementation of Hanoi Tower code about String How to create objects vue3 Learning journey 1—— establish vue3 project java String from back to front _Java String String summary use Python Write a story about plants versus zombies 【 Greedy Algorithm 】 Huffman coding problem