/// <summary> ///get MAC address of native/// </summary> /// <returns></returns> Public Static stringgetmacstring () {ManagementClass madapter=NewManagementClass ("Win32_NetworkAdapterConfiguration"); Managementobjectcollection Mo=madapter.getinstances (); foreach(Managementbaseobject minchmo) { if((BOOL) m["ipenabled"] ==true) { returnm["MacAddress"]. ToString (); }} mo. Dispose (); return NULL; //ManagementClass mc = new ManagementClass ("Win32_NetworkAdapterConfiguration"); //managementobjectcollection MOC = mc. GetInstances (); //foreach (ManagementObject mo in MOC)//{ // //If no IP settings are enabled for network devices, skip//if (! ( BOOL) mo["ipenabled"])//continue; // //Get Properties//String caption = mo["caption"]. ToString (); //name//string[] addresses = (string[]) mo["IPAddress"]; //IP Address//string[] subnets = (string[]) mo["IPSubnet"]; //Subnet Mask//string[] gateways = (string[]) mo["DefaultIPGateway"]; //Gateway//string[] dnses = (string[]) mo["DNSServerSearchOrder"]; //DNS//Managementbaseobject Newip; // //modify IP and subnet masks//NEWIP = mo. Getmethodparameters ("EnableStatic"); //newip["IPAddress"] = new string[] {"192.168.2.51"}; //newip["SubnetMask"] = new string[] {"255.255.255.0"};//Modify IP at the same time, you need to fill in the subnet mask//mo. InvokeMethod ("EnableStatic", NEWIP, NULL); // //Set the gateway address//NEWIP = mo. Getmethodparameters ("SetGateways"); //newip["DefaultIPGateway"] = new string[] {"192.168.2.1"}; //mo. InvokeMethod ("SetGateways", NEWIP, NULL); // //set up DNS//NEWIP = mo. Getmethodparameters ("SetDNSServerSearchOrder"); //newip["DNSServerSearchOrder"] = new string[] {"192.168.1.10"}; //mo. InvokeMethod ("SetDNSServerSearchOrder", NEWIP, null); } /// <summary> ///get the number of CPUs/// </summary> /// <returns></returns> Public Static intGetcpucount () {Try { using(ManagementClass mcpu =NewManagementClass ("Win32_Processor") {managementobjectcollection CPUs=mcpu.getinstances (); returnCPUs. Count; } } Catch { } return-1; } /// <summary> ///how often to get the CPU the use of a string type array is mainly due to the multi-core of the CPU/// </summary> /// <returns></returns> Public Static string[] Getcpumhz () {ManagementClass mc=NewManagementClass ("Win32_Processor"); Managementobjectcollection CPUs=MC. GetInstances (); string[] MHz =New string[CPUs. Count]; intc =0; ManagementObjectSearcher Mysearch=NewManagementObjectSearcher ("SELECT * from Win32_Processor"); foreach(ManagementObject moinchMysearch.get ()) {Mhz[c]= mo. properties["CurrentClockSpeed"]. Value.tostring (); C++; } MC. Dispose (); Mysearch.dispose (); returnmHz; } /// <summary> ///get the size of the hard disk/// </summary> /// <returns></returns> Public Static stringGetsizeofdisk () {ManagementClass mc=NewManagementClass ("win32_diskdrive"); Managementobjectcollection MoJ=MC. GetInstances (); foreach(ManagementObject minchMoJ) { returnm.properties["Size"]. Value.tostring (); } return "-1"; } /// <summary> ///get the size of the memory/// </summary> /// <returns></returns> Public Static stringGetsizeofmemery () {ManagementClass mc=NewManagementClass ("Win32_OperatingSystem"); Managementobjectcollection MOC=MC. GetInstances (); DoubleSizeall =0.0; foreach(ManagementObject minchMOC) { if(m.properties["totalvisiblememorysize"]. Value! =NULL) {Sizeall+ = Convert.todouble (m.properties["totalvisiblememorysize"]. Value.tostring ()); }} MC=NULL; MoC. Dispose (); returnsizeall.tostring (); }
Get the MAC,CPU number of the machine, the CPU number, the hard plate and the memory size