轮胎外观检测添加思谋语义分割模型检测工具
C3204
2026-03-30 06c627ec032b3f3876fd7db8a3ff0ff1a6614fa2
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
 
public class SystemInfoHelper
{
    /// <summary>
    /// 获取计算机用户名
    /// </summary>
    public static string GetComputerUserName()
    {
        return Environment.UserName;
    }
 
    /// <summary>
    /// 获取计算机名
    /// </summary>
    public static string GetComputerName()
    {
        return Environment.MachineName;
    }
 
    /// <summary>
    /// 获取所有MAC地址
    /// </summary>
    public static List<string> GetAllMacAddresses()
    {
        List<string> macAddresses = new List<string>();
 
        try
        {
            NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface ni in interfaces)
            {
                if (ni.OperationalStatus == OperationalStatus.Up &&
                    ni.NetworkInterfaceType != NetworkInterfaceType.Loopback)
                {
                    PhysicalAddress address = ni.GetPhysicalAddress();
                    if (address != null && address.ToString().Length > 0)
                    {
                        string mac = FormatMacAddress(address.ToString());
                        macAddresses.Add(mac);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("获取MAC地址错误: " + ex.Message);
        }
 
        return macAddresses;
    }
 
    /// <summary>
    /// 获取第一个可用的MAC地址
    /// </summary>
    public static string GetFirstMacAddress()
    {
        var macAddresses = GetAllMacAddresses();
        return macAddresses.Count > 0 ? macAddresses[0] : string.Empty;
    }
 
    /// <summary>
    /// 获取所有IP地址(IPv4)
    /// </summary>
    public static List<string> GetAllIPAddresses()
    {
        List<string> ipAddresses = new List<string>();
 
        try
        {
            string hostName = Dns.GetHostName();
            IPAddress[] addresses = Dns.GetHostAddresses(hostName);
 
            foreach (IPAddress address in addresses)
            {
                if (address.AddressFamily == AddressFamily.InterNetwork) // IPv4
                {
                    ipAddresses.Add(address.ToString());
                }
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("获取IP地址错误: " + ex.Message);
        }
 
        return ipAddresses;
    }
 
    /// <summary>
    /// 获取本地IP地址(排除127.0.0.1)
    /// </summary>
    public static string GetLocalIPAddress()
    {
        var ipAddresses = GetAllIPAddresses();
        foreach (string ip in ipAddresses)
        {
            if (ip != "127.0.0.1"
                && !ip.StartsWith("169.254.")
                && !ip.StartsWith("192.168.")) // 排除回环和APIPA地址
            {
                return ip;
            }
        }
        return ipAddresses.Count > 0 ? ipAddresses[0] : string.Empty;
    }
 
    /// <summary>
    /// 格式化MAC地址(添加-分隔符)
    /// </summary>
    private static string FormatMacAddress(string mac)
    {
        if (string.IsNullOrEmpty(mac) || mac.Length != 12)
            return mac;
 
        // 将 "001122AABBCC" 格式化为 "00-11-22-AA-BB-CC"
        return string.Format("{0}-{1}-{2}-{3}-{4}-{5}",
            mac.Substring(0, 2),
            mac.Substring(2, 2),
            mac.Substring(4, 2),
            mac.Substring(6, 2),
            mac.Substring(8, 2),
            mac.Substring(10, 2));
    }
    /// <summary>
    /// 获取所有系统信息
    /// </summary>
    public static Dictionary<string, object> GetAllSystemInfo()
    {
        return new Dictionary<string, object>
        {
            { "UserName", GetComputerUserName() },
            { "ComputerName", GetComputerName() },
            { "MACAddresses", GetAllMacAddresses() },
            { "FirstMACAddress", GetFirstMacAddress() },
            { "IPAddresses", GetAllIPAddresses() },
            { "LocalIPAddress", GetLocalIPAddress() },
            { "OSVersion", Environment.OSVersion.ToString() },
            { "SystemDirectory", Environment.SystemDirectory },
            { "ProcessorCount", Environment.ProcessorCount },
            { "CurrentTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }
        };
    }
}