package com.zy.system.entity.license; import com.core.common.Cools; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.InetAddress; import java.util.List; import java.util.stream.Collectors; public class LinuxServerInfos extends AbstractServerInfos { @Override protected List getIpAddress() throws Exception { List inetAddresses = getLocalAllInetAddress(); if (inetAddresses == null || inetAddresses.isEmpty()) { return null; } return inetAddresses.stream() .map(InetAddress::getHostAddress) .distinct() .map(String::toLowerCase) .collect(Collectors.toList()); } @Override protected List getMacAddress() throws Exception { List inetAddresses = getLocalAllInetAddress(); if (inetAddresses == null || inetAddresses.isEmpty()) { return null; } return inetAddresses.stream() .map(this::getMacByInetAddress) .filter(mac -> mac != null && !mac.trim().isEmpty()) .distinct() .collect(Collectors.toList()); } @Override protected String getCPUSerial() throws Exception { return readFirstNonBlankLine(new String[]{"/bin/bash", "-c", "dmidecode -t processor | grep 'ID' | awk -F ':' '{print $2}' | head -n 1"}); } @Override protected String getMainBoardSerial() throws Exception { return readFirstNonBlankLine(new String[]{"/bin/bash", "-c", "dmidecode | grep 'Serial Number' | awk -F ':' '{print $2}' | head -n 1"}); } private String readFirstNonBlankLine(String[] shell) throws Exception { Process process = Runtime.getRuntime().exec(shell); process.getOutputStream().close(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { String line; while ((line = reader.readLine()) != null) { line = line.trim(); if (!Cools.isEmpty(line)) { return line; } } } return ""; } }