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;
                }
            }

  • 相关阅读:
    当blogger遭遇bXbm42e8
    按时间顺序来,对我影响较大的格言应当首推在高中毕业时霄美人送我的那一句话,它指引着我如何去面对很多难...
    遇见一孙子
    回草儿:呵呵~~这个……随缘。
    学Linux下的编程,make非学好不可啊……
    呵呵,你的口才不错啊!军师,我发现你挺会说话。
    字符串处理的一个简单题
    以Python为基础的REST(JSON为交换数据)接口的测试框架设计(一)
    人生的战略总结最近三年选择的得失
    淘宝开放API初探
  • 原文地址:https://www.cnblogs.com/cuishao1985/p/1343350.html
Copyright © 2011-2022 走看看