zoukankan      html  css  js  c++  java
  • C#.NET GetLocalMachineInfo.cs

     public string[] GetLocalMachineInfo(string Type)
            {
                switch (Type.ToUpper())
                {
                    case "IP":
                        IPHostEntry IPHE = new IPHostEntry();
                        IPHE = Dns.GetHostEntry(Dns.GetHostName());
                        string[] resultIP = new string[IPHE.AddressList.Length];
                        for (int i = 0; i < IPHE.AddressList.Length; i++)
                        {
                            resultIP[i] = IPHE.AddressList[i].ToString();
                        }
                        return resultIP;
                        break;
                    case "MAC":
                        ManagementClass mc;
                        ManagementObjectCollection moc;
                        mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
                        moc = mc.GetInstances();
                        int j = 0;
                        foreach (ManagementObject mo in moc)
                        {
                            if ((bool)mo["IPEnabled"] == true)
                            {
                                j = j + 1;
                            }
                        }
                        string[] resultMac = new string[j];
                        j = 0;
                        foreach (ManagementObject mo in moc)
                        {
                            if ((bool)mo["IPEnabled"] == true)
                            {
                                resultMac[j] = mo["MacAddress"].ToString().Replace(":", "");
                                j = j + 1;
                            }
                        }
                        return resultMac;
                        break;
                    case "HDD":
                        ManagementObject disk;
                        disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
                        disk.Get();
                        string[] resultHDD = new string[1];
                        resultHDD[0] = disk.GetPropertyValue("VolumeSerialNumber").ToString();
                        return resultHDD;
                        break;
                    case "USER":
                        ManagementClass mcUser = new ManagementClass("Win32_ComputerSystem");
                        ManagementObjectCollection mocUser = mcUser.GetInstances();
                        int k = 0;
                        foreach (ManagementObject mo in mocUser)
                        {
                            k = k + 1;
                        }
                        string[] resultUser = new string[k];
                        k = 0;
                        foreach (ManagementObject mo in mocUser)
                        {
                            resultUser[k] = mo["UserName"].ToString();

                            k = k + 1;
                        }
                        return resultUser;
                        break;
                    default:
                        string[] resultNull = new string[1];
                        return resultNull;
                        break;
                }
            }

  • 相关阅读:
    ionic文档
    Can't resolve all parameters for Storage: (?).
    cannot find module @ionicapp-scriptsinionic-app-scripts.js
    ionic 环境搭建
    学习文档记录
    js 文件引用传递参数
    No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
    js 去除左右空格
    sql 多行数据合并
    filter @Autowired nullPointer
  • 原文地址:https://www.cnblogs.com/cuishao1985/p/1343350.html
Copyright © 2011-2022 走看看