From 4792625a3bba5962b22b31edc1f21a4f76ac93b4 Mon Sep 17 00:00:00 2001
From: yangyang
Date: 星期日, 22 六月 2025 10:04:34 +0800
Subject: [PATCH] Merge branch 'ycds-wms-dev' of http://47.97.1.152:5880/r/zy-asrs-master into ycds-wms-dev
---
zy-asrs-wms/src/main/java/com/zy/asrs/wms/system/license/entity/license/SerialNumberUtil.java | 526 +++++++++++++++++++++++++++++-----------------------------
1 files changed, 263 insertions(+), 263 deletions(-)
diff --git a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/system/license/entity/license/SerialNumberUtil.java b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/system/license/entity/license/SerialNumberUtil.java
index f9bc951..afd0f47 100644
--- a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/system/license/entity/license/SerialNumberUtil.java
+++ b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/system/license/entity/license/SerialNumberUtil.java
@@ -1,263 +1,263 @@
-package com.zy.asrs.wms.system.license.entity.license;
-
-import java.io.*;
-import java.net.*;
-import java.util.*;
-
-public class SerialNumberUtil {
-
-
- /**
- * 鑾峰彇涓绘澘搴忓垪鍙�
- *
- * @return
- */
- public static String getMotherboardSN() {
- String result = "";
- try {
- File file = File.createTempFile("realhowto", ".vbs");
- file.deleteOnExit();
- FileWriter fw = new FileWriter(file);
-
- String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n" + "Set colItems = objWMIService.ExecQuery _ \n" + " (\"Select * from Win32_BaseBoard\") \n" + "For Each objItem in colItems \n" + " Wscript.Echo objItem.SerialNumber \n" + " exit for ' do the first cpu only! \n" + "Next \n";
-
- fw.write(vbs);
- fw.close();
- String path = file.getPath().replace("%20", " ");
- Process p = Runtime.getRuntime().exec("cscript //NoLogo " + path);
- BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
- String line;
- while ((line = input.readLine()) != null) {
- result += line;
- }
- input.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return result.trim();
- }
-
- /**
- * 鑾峰彇纭洏搴忓垪鍙�(璇ユ柟娉曡幏鍙栫殑鏄� 鐩樼鐨勯�昏緫搴忓垪鍙�,骞朵笉鏄‖鐩樻湰韬殑搴忓垪鍙�)
- * 纭洏搴忓垪鍙疯繕鍦ㄧ爺绌朵腑
- *
- * @param drive 鐩樼
- * @return
- */
- public static String getHardDiskSN(String drive) {
- String result = "";
- try {
- File file = File.createTempFile("realhowto", ".vbs");
- file.deleteOnExit();
- FileWriter fw = new FileWriter(file);
-
- String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n" + "Set colDrives = objFSO.Drives\n" + "Set objDrive = colDrives.item(\"" + drive + "\")\n" + "Wscript.Echo objDrive.SerialNumber"; // see note
- fw.write(vbs);
- fw.close();
- String path = file.getPath().replace("%20", " ");
- Process p = Runtime.getRuntime().exec("cscript //NoLogo " + path);
- BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
- String line;
- while ((line = input.readLine()) != null) {
- result += line;
- }
- input.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return result.trim();
- }
-
- /**
- * 鑾峰彇CPU搴忓垪鍙�
- *
- * @return
- */
- public static String getCPUSerial() {
- String result = "";
- try {
- File file = File.createTempFile("tmp", ".vbs");
- file.deleteOnExit();
- FileWriter fw = new FileWriter(file);
- String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n" + "Set colItems = objWMIService.ExecQuery _ \n" + " (\"Select * from Win32_Processor\") \n" + "For Each objItem in colItems \n" + " Wscript.Echo objItem.ProcessorId \n" + " exit for ' do the first cpu only! \n" + "Next \n";
-
- // + " exit for \r\n" + "Next";
- fw.write(vbs);
- fw.close();
- String path = file.getPath().replace("%20", " ");
- Process p = Runtime.getRuntime().exec("cscript //NoLogo " + path);
- BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
- String line;
- while ((line = input.readLine()) != null) {
- result += line;
- }
- input.close();
- file.delete();
- } catch (Exception e) {
- e.fillInStackTrace();
- }
- if (result.trim().length() < 1 || result == null) {
- result = "鏃燙PU_ID琚鍙�";
- }
- return result.trim();
- }
-
- private static List<String> getLocalHostLANAddress() throws UnknownHostException, SocketException {
- List<String> ips = new ArrayList<String>();
- Enumeration<NetworkInterface> interfs = NetworkInterface.getNetworkInterfaces();
- while (interfs.hasMoreElements()) {
- NetworkInterface interf = interfs.nextElement();
- Enumeration<InetAddress> addres = interf.getInetAddresses();
- while (addres.hasMoreElements()) {
- InetAddress in = addres.nextElement();
- if (in instanceof Inet4Address) {
- System.out.println("v4:" + in.getHostAddress());
- if (!"127.0.0.1".equals(in.getHostAddress())) {
- ips.add(in.getHostAddress());
- }
- }
- }
- }
- return ips;
- }
-
- /**
- * MAC
- * 閫氳繃jdk鑷甫鐨勬柟娉�,鍏堣幏鍙栨湰鏈烘墍鏈夌殑ip,鐒跺悗閫氳繃NetworkInterface鑾峰彇mac鍦板潃
- *
- * @return
- */
- public static String getMac() {
- try {
- String resultStr = "";
- List<String> ls = getLocalHostLANAddress();
- for (String str : ls) {
- InetAddress ia = InetAddress.getByName(str);// 鑾峰彇鏈湴IP瀵硅薄
- // 鑾峰緱缃戠粶鎺ュ彛瀵硅薄锛堝嵆缃戝崱锛夛紝骞跺緱鍒癿ac鍦板潃锛宮ac鍦板潃瀛樺湪浜庝竴涓猙yte鏁扮粍涓��
- byte[] mac = NetworkInterface.getByInetAddress(ia).getHardwareAddress();
- // 涓嬮潰浠g爜鏄妸mac鍦板潃鎷艰鎴怱tring
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < mac.length; i++) {
- if (i != 0) {
- sb.append("-");
- }
- // mac[i] & 0xFF 鏄负浜嗘妸byte杞寲涓烘鏁存暟
- String s = Integer.toHexString(mac[i] & 0xFF);
- sb.append(s.length() == 1 ? 0 + s : s);
- }
- // 鎶婂瓧绗︿覆鎵�鏈夊皬鍐欏瓧姣嶆敼涓哄ぇ鍐欐垚涓烘瑙勭殑mac鍦板潃骞惰繑鍥�
- resultStr += sb.toString().toUpperCase() + ",";
- }
- return resultStr;
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- return null;
- }
-
- /***************************linux*********************************/
-
- public static String executeLinuxCmd(String cmd) {
- try {
- //System.out.println("got cmd job : " + cmd);
- Runtime run = Runtime.getRuntime();
- Process process;
- process = run.exec(cmd);
- InputStream in = process.getInputStream();
- BufferedReader bs = new BufferedReader(new InputStreamReader(in));
- StringBuffer out = new StringBuffer();
- byte[] b = new byte[8192];
- for (int n; (n = in.read(b)) != -1; ) {
- out.append(new String(b, 0, n));
- }
- in.close();
- process.destroy();
- return out.toString();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- /**
- * @param cmd 鍛戒护璇彞
- * @param record 瑕佹煡鐪嬬殑瀛楁
- * @param symbol 鍒嗛殧绗�
- * @return
- */
- public static String getSerialNumber(String cmd, String record, String symbol) {
- String execResult = executeLinuxCmd(cmd);
- String[] infos = execResult.split("\n");
-
- for (String info : infos) {
- info = info.trim();
- if (info.indexOf(record) != -1) {
- info.replace(" ", "");
- String[] sn = info.split(symbol);
- return sn[1];
- }
- }
-
- return null;
- }
-
- /**
- * 鑾峰彇CPUID銆佺‖鐩樺簭鍒楀彿銆丮AC鍦板潃銆佷富鏉垮簭鍒楀彿
- *
- * @return
- */
- public static Map<String, String> getAllSn() {
- String os = System.getProperty("os.name");
- os = os.toUpperCase();
- System.out.println(os);
-
- Map<String, String> snVo = new HashMap<String, String>();
-
- if (os.contains("LINUX")) {
- System.out.println("=============>for linux");
- String cpuid = getSerialNumber("dmidecode -t processor | grep 'ID'", "ID", ":");
- System.out.println("cpuid : " + cpuid);
- String mainboardNumber = getSerialNumber("dmidecode |grep 'Serial Number'", "Serial Number", ":");
- System.out.println("mainboardNumber : " + mainboardNumber);
- String diskNumber = getSerialNumber("fdisk -l", "Disk identifier", ":");
- System.out.println("diskNumber : " + diskNumber);
- String mac = getSerialNumber("ifconfig -a", "ether", " ");
-
- snVo.put("cpuid", cpuid.toUpperCase().replace(" ", ""));
- snVo.put("diskid", diskNumber.toUpperCase().replace(" ", ""));
- snVo.put("mac", mac.toUpperCase().replace(" ", ""));
- snVo.put("mainboard", mainboardNumber.toUpperCase().replace(" ", ""));
- } else {
- System.out.println("=============>for windows");
- String cpuid = SerialNumberUtil.getCPUSerial();
- String mainboard = SerialNumberUtil.getMotherboardSN();
- String disk = SerialNumberUtil.getHardDiskSN("c");
- String mac = SerialNumberUtil.getMac();
-
- System.out.println("CPU SN:" + cpuid);
- System.out.println("涓绘澘 SN:" + mainboard);
- System.out.println("C鐩� SN:" + disk);
- System.out.println("MAC SN:" + mac);
-
- snVo.put("cpuid", cpuid.toUpperCase().replace(" ", ""));
- snVo.put("diskid", disk.toUpperCase().replace(" ", ""));
- snVo.put("mac", mac.toUpperCase().replace(" ", ""));
- snVo.put("mainboard", mainboard.toUpperCase().replace(" ", ""));
- }
-
- return snVo;
- }
-
- /**
- * linux
- * cpuid : dmidecode -t processor | grep 'ID'
- * mainboard : dmidecode |grep 'Serial Number'
- * disk : fdisk -l
- * mac : ifconfig -a
- *
- * @param args
- */
- public static void main(String[] args) {
- getAllSn();
- }
-}
+package com.zy.asrs.wms.system.license.entity.license;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+
+public class SerialNumberUtil {
+
+
+ /**
+ * 鑾峰彇涓绘澘搴忓垪鍙�
+ *
+ * @return
+ */
+ public static String getMotherboardSN() {
+ String result = "";
+ try {
+ File file = File.createTempFile("realhowto", ".vbs");
+ file.deleteOnExit();
+ FileWriter fw = new FileWriter(file);
+
+ String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n" + "Set colItems = objWMIService.ExecQuery _ \n" + " (\"Select * from Win32_BaseBoard\") \n" + "For Each objItem in colItems \n" + " Wscript.Echo objItem.SerialNumber \n" + " exit for ' do the first cpu only! \n" + "Next \n";
+
+ fw.write(vbs);
+ fw.close();
+ String path = file.getPath().replace("%20", " ");
+ Process p = Runtime.getRuntime().exec("cscript //NoLogo " + path);
+ BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ String line;
+ while ((line = input.readLine()) != null) {
+ result += line;
+ }
+ input.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return result.trim();
+ }
+
+ /**
+ * 鑾峰彇纭洏搴忓垪鍙�(璇ユ柟娉曡幏鍙栫殑鏄� 鐩樼鐨勯�昏緫搴忓垪鍙�,骞朵笉鏄‖鐩樻湰韬殑搴忓垪鍙�)
+ * 纭洏搴忓垪鍙疯繕鍦ㄧ爺绌朵腑
+ *
+ * @param drive 鐩樼
+ * @return
+ */
+ public static String getHardDiskSN(String drive) {
+ String result = "";
+ try {
+ File file = File.createTempFile("realhowto", ".vbs");
+ file.deleteOnExit();
+ FileWriter fw = new FileWriter(file);
+
+ String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n" + "Set colDrives = objFSO.Drives\n" + "Set objDrive = colDrives.item(\"" + drive + "\")\n" + "Wscript.Echo objDrive.SerialNumber"; // see note
+ fw.write(vbs);
+ fw.close();
+ String path = file.getPath().replace("%20", " ");
+ Process p = Runtime.getRuntime().exec("cscript //NoLogo " + path);
+ BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ String line;
+ while ((line = input.readLine()) != null) {
+ result += line;
+ }
+ input.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return result.trim();
+ }
+
+ /**
+ * 鑾峰彇CPU搴忓垪鍙�
+ *
+ * @return
+ */
+ public static String getCPUSerial() {
+ String result = "";
+ try {
+ File file = File.createTempFile("tmp", ".vbs");
+ file.deleteOnExit();
+ FileWriter fw = new FileWriter(file);
+ String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n" + "Set colItems = objWMIService.ExecQuery _ \n" + " (\"Select * from Win32_Processor\") \n" + "For Each objItem in colItems \n" + " Wscript.Echo objItem.ProcessorId \n" + " exit for ' do the first cpu only! \n" + "Next \n";
+
+ // + " exit for \r\n" + "Next";
+ fw.write(vbs);
+ fw.close();
+ String path = file.getPath().replace("%20", " ");
+ Process p = Runtime.getRuntime().exec("cscript //NoLogo " + path);
+ BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ String line;
+ while ((line = input.readLine()) != null) {
+ result += line;
+ }
+ input.close();
+ file.delete();
+ } catch (Exception e) {
+ e.fillInStackTrace();
+ }
+ if (result.trim().length() < 1 || result == null) {
+ result = "鏃燙PU_ID琚鍙�";
+ }
+ return result.trim();
+ }
+
+ private static List<String> getLocalHostLANAddress() throws UnknownHostException, SocketException {
+ List<String> ips = new ArrayList<String>();
+ Enumeration<NetworkInterface> interfs = NetworkInterface.getNetworkInterfaces();
+ while (interfs.hasMoreElements()) {
+ NetworkInterface interf = interfs.nextElement();
+ Enumeration<InetAddress> addres = interf.getInetAddresses();
+ while (addres.hasMoreElements()) {
+ InetAddress in = addres.nextElement();
+ if (in instanceof Inet4Address) {
+ System.out.println("v4:" + in.getHostAddress());
+ if (!"127.0.0.1".equals(in.getHostAddress())) {
+ ips.add(in.getHostAddress());
+ }
+ }
+ }
+ }
+ return ips;
+ }
+
+ /**
+ * MAC
+ * 閫氳繃jdk鑷甫鐨勬柟娉�,鍏堣幏鍙栨湰鏈烘墍鏈夌殑ip,鐒跺悗閫氳繃NetworkInterface鑾峰彇mac鍦板潃
+ *
+ * @return
+ */
+ public static String getMac() {
+ try {
+ String resultStr = "";
+ List<String> ls = getLocalHostLANAddress();
+ for (String str : ls) {
+ InetAddress ia = InetAddress.getByName(str);// 鑾峰彇鏈湴IP瀵硅薄
+ // 鑾峰緱缃戠粶鎺ュ彛瀵硅薄锛堝嵆缃戝崱锛夛紝骞跺緱鍒癿ac鍦板潃锛宮ac鍦板潃瀛樺湪浜庝竴涓猙yte鏁扮粍涓��
+ byte[] mac = NetworkInterface.getByInetAddress(ia).getHardwareAddress();
+ // 涓嬮潰浠g爜鏄妸mac鍦板潃鎷艰鎴怱tring
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < mac.length; i++) {
+ if (i != 0) {
+ sb.append("-");
+ }
+ // mac[i] & 0xFF 鏄负浜嗘妸byte杞寲涓烘鏁存暟
+ String s = Integer.toHexString(mac[i] & 0xFF);
+ sb.append(s.length() == 1 ? 0 + s : s);
+ }
+ // 鎶婂瓧绗︿覆鎵�鏈夊皬鍐欏瓧姣嶆敼涓哄ぇ鍐欐垚涓烘瑙勭殑mac鍦板潃骞惰繑鍥�
+ resultStr += sb.toString().toUpperCase() + ",";
+ }
+ return resultStr;
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+
+ /***************************linux*********************************/
+
+ public static String executeLinuxCmd(String cmd) {
+ try {
+ //System.out.println("got cmd job : " + cmd);
+ Runtime run = Runtime.getRuntime();
+ Process process;
+ process = run.exec(cmd);
+ InputStream in = process.getInputStream();
+ BufferedReader bs = new BufferedReader(new InputStreamReader(in));
+ StringBuffer out = new StringBuffer();
+ byte[] b = new byte[8192];
+ for (int n; (n = in.read(b)) != -1; ) {
+ out.append(new String(b, 0, n));
+ }
+ in.close();
+ process.destroy();
+ return out.toString();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * @param cmd 鍛戒护璇彞
+ * @param record 瑕佹煡鐪嬬殑瀛楁
+ * @param symbol 鍒嗛殧绗�
+ * @return
+ */
+ public static String getSerialNumber(String cmd, String record, String symbol) {
+ String execResult = executeLinuxCmd(cmd);
+ String[] infos = execResult.split("\n");
+
+ for (String info : infos) {
+ info = info.trim();
+ if (info.indexOf(record) != -1) {
+ info.replace(" ", "");
+ String[] sn = info.split(symbol);
+ return sn[1];
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * 鑾峰彇CPUID銆佺‖鐩樺簭鍒楀彿銆丮AC鍦板潃銆佷富鏉垮簭鍒楀彿
+ *
+ * @return
+ */
+ public static Map<String, String> getAllSn() {
+ String os = System.getProperty("os.name");
+ os = os.toUpperCase();
+ System.out.println(os);
+
+ Map<String, String> snVo = new HashMap<String, String>();
+
+ if (os.contains("LINUX")) {
+ System.out.println("=============>for linux");
+ String cpuid = getSerialNumber("dmidecode -t processor | grep 'ID'", "ID", ":");
+ System.out.println("cpuid : " + cpuid);
+ String mainboardNumber = getSerialNumber("dmidecode |grep 'Serial Number'", "Serial Number", ":");
+ System.out.println("mainboardNumber : " + mainboardNumber);
+ String diskNumber = getSerialNumber("fdisk -l", "Disk identifier", ":");
+ System.out.println("diskNumber : " + diskNumber);
+ String mac = getSerialNumber("ifconfig -a", "ether", " ");
+
+ snVo.put("cpuid", cpuid.toUpperCase().replace(" ", ""));
+ snVo.put("diskid", diskNumber.toUpperCase().replace(" ", ""));
+ snVo.put("mac", mac.toUpperCase().replace(" ", ""));
+ snVo.put("mainboard", mainboardNumber.toUpperCase().replace(" ", ""));
+ } else {
+ System.out.println("=============>for windows");
+ String cpuid = SerialNumberUtil.getCPUSerial();
+ String mainboard = SerialNumberUtil.getMotherboardSN();
+ String disk = SerialNumberUtil.getHardDiskSN("c");
+ String mac = SerialNumberUtil.getMac();
+
+ System.out.println("CPU SN:" + cpuid);
+ System.out.println("涓绘澘 SN:" + mainboard);
+ System.out.println("C鐩� SN:" + disk);
+ System.out.println("MAC SN:" + mac);
+
+ snVo.put("cpuid", cpuid.toUpperCase().replace(" ", ""));
+ snVo.put("diskid", disk.toUpperCase().replace(" ", ""));
+ snVo.put("mac", mac.toUpperCase().replace(" ", ""));
+ snVo.put("mainboard", mainboard.toUpperCase().replace(" ", ""));
+ }
+
+ return snVo;
+ }
+
+ /**
+ * linux
+ * cpuid : dmidecode -t processor | grep 'ID'
+ * mainboard : dmidecode |grep 'Serial Number'
+ * disk : fdisk -l
+ * mac : ifconfig -a
+ *
+ * @param args
+ */
+ public static void main(String[] args) {
+ getAllSn();
+ }
+}
--
Gitblit v1.9.1