From c635d78b479510ebe2556a420948effcd30a0731 Mon Sep 17 00:00:00 2001 From: skyouc Date: 星期六, 21 十二月 2024 18:40:43 +0800 Subject: [PATCH] 新建德森项目分支 --- zy-asrs-wms/src/main/java/com/zy/asrs/wms/system/license/entity/license/AbstractServerInfos.java | 220 +++++++++++++++++++++++++++--------------------------- 1 files changed, 110 insertions(+), 110 deletions(-) diff --git a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/system/license/entity/license/AbstractServerInfos.java b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/system/license/entity/license/AbstractServerInfos.java index 299818e..ebde1a0 100644 --- a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/system/license/entity/license/AbstractServerInfos.java +++ b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/system/license/entity/license/AbstractServerInfos.java @@ -1,111 +1,111 @@ -package com.zy.asrs.wms.system.license.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(); - 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; - } - +package com.zy.asrs.wms.system.license.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(); + 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