下面放出Unity获取安卓mac地址源码供大家参考学习,如果有更好、更快的方法能获取到MaC地址的话,请一定要分享出来哦,好了,直接上源码。

首先在添加引用中选中System.Management

  1. using System.Management;
  2. using System.Management.Instrumentation;
  3. private void GetInfo()  
  4.    {  
  5.     string cpuInfo = "";//cpu序列号  
  6.     ManagementClass cimobject = new ManagementClass("Win32_Processor");  
  7.     ManagementObjectCollection moc = cimobject.GetInstances();  
  8.     foreach(ManagementObject mo in moc)  
  9.     {  
  10.      cpuInfo = mo.Properties["ProcessorId"].Value.ToString();  
  11.      Response.Write ("cpu序列号:"+cpuInfo.ToString ());  
  12.     } 
  13.     //获取硬盘ID  
  14.     String HDid;  
  15.     ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");  
  16.     ManagementObjectCollection moc1 = cimobject1.GetInstances();  
  17.     foreach(ManagementObject mo in moc1)  
  18.     {  
  19.      HDid = (string)mo.Properties["Model"].Value;  
  20.      Response.Write ("硬盘序列号:"+HDid.ToString ());  
  21.     } 

  22.     //获取网卡硬件地址 


  23.     ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");  
  24.     ManagementObjectCollection moc2 = mc.GetInstances();  
  25.     foreach(ManagementObject mo in moc2)  
  26.     {  
  27.      if((bool)mo["IPEnabled"] == true)  
  28.       Response.Write("MAC address\t{0}"+mo["MacAddress"].ToString());  
  29.      mo.Dispose();  
  30.     }  
  31.    }

  32.     public static float GetCPUPersent()
  33.     {
  34.         float cpuload = 0;
  35.         const string categoryname = "processor";
  36.         const string countername = "% processor time";
  37.         const string instancename = "_total";
  38.         PerformanceCounter pc = new PerformanceCounter(categoryname, countername, instancename);
  39.         int i = 10;
  40.         while (i > 0)
  41.         {
  42.             Thread.Sleep(1000); // wait for 1 second 
  43.             cpuload = pc.NextValue();
  44.             if (cpuload > 0)
  45.             {
  46.                 break;
  47.             }
  48.             i--;
  49.         }
  50.         return cpuload;
  51.     }
  52.     public static void GetDiskSpace(string path, out long DiskAll, out long DiskActive)
  53.     {
  54.         DiskAll = 0;
  55.         DiskActive = 0;
  56.         long a, b, c;
  57.         int aaa = GetDiskFreeSpaceEx(path, out a, out b, out c);
  58.         DiskAll = (long)(b / 1024 / 1024);
  59.         DiskActive = (long)(a / 1024 / 1024);
  60.     }
  61.     public static void GetMemoryInfo(out uint MemoryAll, out uint MemoryUsed)
  62.     {
  63.         MemoryAll = 0;
  64.         MemoryUsed = 0;
  65.         MEMORY_INFO MemInfo = new MEMORY_INFO();
  66.         GlobalMemoryStatus(ref  MemInfo);
  67.         MemoryAll = MemInfo.dwTotalPhys / 1024 / 1024;
  68.         MemoryUsed = (MemInfo.dwTotalPhys - MemInfo.dwAvailPhys) / 1024 / 1024;
  69.     }



  70.     [DllImport("kernel32")]
  71.     public static extern void GlobalMemoryStatus(ref  MEMORY_INFO meminfo);
  72.     //定义内存的信息结构  
  73.     [StructLayout(LayoutKind.Sequential)]
  74.     public struct MEMORY_INFO
  75.     {
  76.         public uint dwLength;
  77.         public uint dwMemoryLoad;
  78.         public uint dwTotalPhys;
  79.         public uint dwAvailPhys;
  80.         public uint dwTotalPageFile;
  81.         public uint dwAvailPageFile;
  82.         public uint dwTotalVirtual;
  83.         public uint dwAvailVirtual;
  84.     }
  85.     [DllImport("kernel32.dll", EntryPoint = "GetDiskFreeSpaceExA")]
  86.     public static extern int GetDiskFreeSpaceEx(string lpRootPathName, out long lpFreeBytesAvailable, out long lpTotalNumberOfBytes, out long lpTotalNumberOfFreeBytes);
以上就是Unity获取安卓mac地址源码的内容,如果我有优化更好地源码的话,也会第一时间分享给大家,。