5 changed files with 76 additions and 1 deletions
-
29common/src/main/java/com/storeroom/utils/MacUtil.java
-
17common/src/test/java/TestMacAddress.java
-
20storeroom/src/main/java/com/storeroom/modules/device/service/DeviceService.java
-
9storeroom/src/main/java/com/storeroom/modules/device/service/impl/DeviceImpl.java
-
2storeroom/src/main/java/com/storeroom/modules/device/service/impl/DeviceSpecParamImpl.java
@ -0,0 +1,29 @@ |
|||
package com.storeroom.utils; |
|||
|
|||
|
|||
import java.net.InetAddress; |
|||
import java.net.NetworkInterface; |
|||
|
|||
public final class MacUtil { |
|||
|
|||
|
|||
|
|||
/** |
|||
* 根据不同操作系统执行不同命令 |
|||
* 获取本机 mac 地址集合 |
|||
* |
|||
* @return mac 地址集合 |
|||
*/ |
|||
public static String getMac() throws Exception { |
|||
|
|||
InetAddress ip = InetAddress.getLocalHost(); |
|||
NetworkInterface network = NetworkInterface.getByInetAddress(ip); |
|||
byte[] mac = network.getHardwareAddress(); |
|||
StringBuilder sb = new StringBuilder(); |
|||
for (int i = 0; i < mac.length; i++) { |
|||
sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "")); |
|||
} |
|||
|
|||
return sb.toString(); |
|||
} |
|||
} |
@ -0,0 +1,17 @@ |
|||
import com.storeroom.utils.MacUtil; |
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
|
|||
|
|||
public class TestMacAddress { |
|||
|
|||
|
|||
@Test |
|||
public void getMac(){ |
|||
try { |
|||
System.out.println(MacUtil.getMac()); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue