获取服务器的MAC地址,(获取程序所在机器的MAC地址,不能用VS调试使用)
/// <summary> /// 获取服务器的IP地址 /// </summary> /// <returns></returns> protected string GetServerIP() { return Request.ServerVariables["Local_Addr"]; } /// <summary> /// 获取服务器的MAC地址 /// </summary> /// <param name="clientIp"></param> /// <returns></returns> protected string GetMac(string serverIp) { if (serverIp != "") { return ""; } string mac = ""; string query = "select MACAddress from Win32_NetworkAdapterConfiguration where IPEnabled='TRUE'"; System.Management.ManagementObjectSearcher searcher = new ManagementObjectSearcher(query); ManagementObjectCollection collection = searcher.Get(); foreach (ManagementObject mo in collection) { mac = mo["MACAddress"].ToString(); } return mac; }