From 48c1de18235020edff108339ed1d12bade8a2b90 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期一, 08 十二月 2025 16:37:02 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/system/entity/license/AbstractServerInfos.java | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 115 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/zy/system/entity/license/AbstractServerInfos.java b/src/main/java/com/zy/system/entity/license/AbstractServerInfos.java
new file mode 100644
index 0000000..be84610
--- /dev/null
+++ b/src/main/java/com/zy/system/entity/license/AbstractServerInfos.java
@@ -0,0 +1,115 @@
+package com.zy.system.entity.license;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+/**
+ * 鐢ㄤ簬鑾峰彇瀹㈡埛鏈嶅姟鍣ㄧ殑鍩烘湰淇℃伅锛屽锛欼P銆丮ac鍦板潃銆丆PU搴忓垪鍙枫�佷富鏉垮簭鍒楀彿绛�
+ */
+public abstract class AbstractServerInfos {
+ private static Logger logger = LogManager.getLogger(AbstractServerInfos.class);
+
+ /**
+ * 缁勮闇�瑕侀澶栨牎楠岀殑License鍙傛暟
+ */
+ public LicenseCheck getServerInfos(){
+ LicenseCheck result = new LicenseCheck();
+
+ try {
+// result.setIpAddress(this.getIpAddress());
+ result.setMacAddress(this.getMacAddress());
+ result.setCpuSerial(this.getCPUSerial());
+ result.setMainBoardSerial(this.getMainBoardSerial());
+ }catch (Exception e){
+ logger.error("鑾峰彇鏈嶅姟鍣ㄧ‖浠朵俊鎭け璐�",e);
+ }
+
+ return result;
+ }
+
+ /**
+ * 鑾峰彇IP鍦板潃
+ */
+ protected abstract List<String> getIpAddress() throws Exception;
+
+ /**
+ * 鑾峰彇Mac鍦板潃
+ */
+ protected abstract List<String> getMacAddress() throws Exception;
+
+ /**
+ * 鑾峰彇CPU搴忓垪鍙�
+ */
+ protected abstract String getCPUSerial() throws Exception;
+
+ /**
+ * 鑾峰彇涓绘澘搴忓垪鍙�
+ */
+ protected abstract String getMainBoardSerial() throws Exception;
+
+ /**
+ * 鑾峰彇褰撳墠鏈嶅姟鍣ㄦ墍鏈夌鍚堟潯浠剁殑InetAddress
+ */
+ protected List<InetAddress> getLocalAllInetAddress() throws Exception {
+ List<InetAddress> result = new ArrayList<>(4);
+
+ // 閬嶅巻鎵�鏈夌殑缃戠粶鎺ュ彛
+ for (Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); networkInterfaces.hasMoreElements(); ) {
+ NetworkInterface iface = (NetworkInterface) networkInterfaces.nextElement();
+ // 鍦ㄦ墍鏈夌殑鎺ュ彛涓嬪啀閬嶅巻IP
+ for (Enumeration inetAddresses = iface.getInetAddresses(); inetAddresses.hasMoreElements(); ) {
+ InetAddress inetAddr = (InetAddress) inetAddresses.nextElement();
+
+ //鎺掗櫎LoopbackAddress銆丼iteLocalAddress銆丩inkLocalAddress銆丮ulticastAddress绫诲瀷鐨処P鍦板潃
+ if(!inetAddr.isLoopbackAddress() /*&& !inetAddr.isSiteLocalAddress()*/
+ && !inetAddr.isLinkLocalAddress() && !inetAddr.isMulticastAddress()){
+ result.add(inetAddr);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * 鑾峰彇鏌愪釜缃戠粶鎺ュ彛鐨凪ac鍦板潃
+ */
+ protected String getMacByInetAddress(InetAddress inetAddr){
+ try {
+ byte[] mac = NetworkInterface.getByInetAddress(inetAddr).getHardwareAddress();
+ if (mac == null) {
+ return null;
+ }
+
+ StringBuffer stringBuffer = new StringBuffer();
+
+ for(int i=0;i<mac.length;i++){
+ if(i != 0) {
+ stringBuffer.append("-");
+ }
+
+ //灏嗗崄鍏繘鍒禸yte杞寲涓哄瓧绗︿覆
+ String temp = Integer.toHexString(mac[i] & 0xff);
+ if(temp.length() == 1){
+ stringBuffer.append("0" + temp);
+ }else{
+ stringBuffer.append(temp);
+ }
+ }
+
+ return stringBuffer.toString().toUpperCase();
+ } catch (SocketException e) {
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+}
\ No newline at end of file
--
Gitblit v1.9.1