自动化立体仓库 - WMS系统
zwl
昨天 780ff45fdc167cadf4724c6c94530929b7445aab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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<String> getIpAddress() throws Exception {
        List<InetAddress> 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<String> getMacAddress() throws Exception {
        List<InetAddress> 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 "";
    }
}