| | |
| | | package com.zy.system.entity.license; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.InputStreamReader; |
| | | import java.net.InetAddress; |
| | | import java.nio.charset.Charset; |
| | | import java.util.List; |
| | | import java.util.Scanner; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | |
| | | if(inetAddresses != null && inetAddresses.size() > 0){ |
| | | //2. 获取所有网络接口的Mac地址 |
| | | result = inetAddresses.stream().map(this::getMacByInetAddress).distinct().collect(Collectors.toList()); |
| | | result = inetAddresses.stream() |
| | | .map(this::getMacByInetAddress) |
| | | .filter(mac -> mac != null && !mac.trim().isEmpty()) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | return result; |
| | |
| | | |
| | | @Override |
| | | protected String getCPUSerial() throws Exception { |
| | | //序列号 |
| | | String serialNumber = ""; |
| | | |
| | | //使用WMIC获取CPU序列号 |
| | | Process process = Runtime.getRuntime().exec("wmic cpu get processorid"); |
| | | process.getOutputStream().close(); |
| | | Scanner scanner = new Scanner(process.getInputStream()); |
| | | |
| | | if(scanner.hasNext()){ |
| | | scanner.next(); |
| | | } |
| | | |
| | | if(scanner.hasNext()){ |
| | | serialNumber = scanner.next().trim(); |
| | | } |
| | | |
| | | scanner.close(); |
| | | String serialNumber = readCommandValue("wmic", "cpu", "get", "processorid"); |
| | | if (!isBlank(serialNumber)) { |
| | | return serialNumber; |
| | | } |
| | | return readCommandValue("powershell", "-NoProfile", "-Command", |
| | | "(Get-CimInstance Win32_Processor | Select-Object -First 1 -ExpandProperty ProcessorId)"); |
| | | } |
| | | |
| | | @Override |
| | | protected String getMainBoardSerial() throws Exception { |
| | | //序列号 |
| | | String serialNumber = ""; |
| | | |
| | | //使用WMIC获取主板序列号 |
| | | Process process = Runtime.getRuntime().exec("wmic baseboard get serialnumber"); |
| | | process.getOutputStream().close(); |
| | | Scanner scanner = new Scanner(process.getInputStream()); |
| | | |
| | | if(scanner.hasNext()){ |
| | | scanner.next(); |
| | | } |
| | | |
| | | if(scanner.hasNext()){ |
| | | serialNumber = scanner.next().trim(); |
| | | } |
| | | |
| | | scanner.close(); |
| | | String serialNumber = readCommandValue("wmic", "baseboard", "get", "serialnumber"); |
| | | if (!isBlank(serialNumber)) { |
| | | return serialNumber; |
| | | } |
| | | return readCommandValue("powershell", "-NoProfile", "-Command", |
| | | "(Get-CimInstance Win32_BaseBoard | Select-Object -First 1 -ExpandProperty SerialNumber)"); |
| | | } |
| | | |
| | | private String readCommandValue(String... command) { |
| | | try { |
| | | ProcessBuilder processBuilder = new ProcessBuilder(command); |
| | | processBuilder.redirectErrorStream(true); |
| | | Process process = processBuilder.start(); |
| | | process.getOutputStream().close(); |
| | | |
| | | try (BufferedReader reader = new BufferedReader( |
| | | new InputStreamReader(process.getInputStream(), Charset.forName("GBK")))) { |
| | | String line; |
| | | while ((line = reader.readLine()) != null) { |
| | | String value = normalizeCommandOutput(line); |
| | | if (!isBlank(value)) { |
| | | return value; |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception ignored) { |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | private String normalizeCommandOutput(String line) { |
| | | if (line == null) { |
| | | return ""; |
| | | } |
| | | String value = line.trim(); |
| | | if (isBlank(value)) { |
| | | return ""; |
| | | } |
| | | String lower = value.toLowerCase(); |
| | | if ("processorid".equals(lower) || "serialnumber".equals(lower)) { |
| | | return ""; |
| | | } |
| | | if (lower.contains("access denied") |
| | | || lower.contains("拒绝访问") |
| | | || lower.contains("get-ciminstance") |
| | | || lower.contains("fullyqualifiederrorid") |
| | | || lower.contains("at line:") |
| | | || lower.contains("categoryinfo") |
| | | || lower.contains("cimexception") |
| | | || lower.contains("createprocess error")) { |
| | | return ""; |
| | | } |
| | | return value; |
| | | } |
| | | |
| | | private boolean isBlank(String value) { |
| | | return value == null || value.trim().isEmpty(); |
| | | } |
| | | } |