- public static string ServerIP()
- {
- string text = HttpContext.Current.Request.ServerVariables.Get("Local_Addr").ToString();
- if (text.Length < 7)
- {
- ManagementClass managementClass = new ManagementClass("Win32_NetworkAdapterConfiguration");
- ManagementObjectCollection instances = managementClass.GetInstances();
- using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = instances.GetEnumerator())
- {
- while (enumerator.MoveNext())
- {
- ManagementObject managementObject = (ManagementObject)enumerator.Current;
- if ((bool)managementObject["IPEnabled"])
- {
- string[] array = (string[])managementObject["IPAddress"];
- if (array.Length > 0)
- {
- text = array[0];
- }
- break;
- }
- }
- }
- }
- return text;
- }
- //该片段来自于http://www.codesnippet.cn/detail/1907201614884.html
来源: http://www.codesnippet.cn/detail/1907201614884.html