获取请求页面内网ip外网ip
/// <summary> /// 获取内网IP /// </summary> /// <returns></returns> public static string GetInternalIP() { IPHostEntry host; string localIP = "?"; host = Dns.GetHostEntry(Dns.GetHostName()); foreach (IPAddress ip in host.AddressList) { if (ip.AddressFamily.ToString() == "InterNetwork") { localIP = ip.ToString(); break; } } return localIP; } /// <summary> /// 获取外网IP /// </summary> /// <returns></returns> public static string GetExternalIP() { string result = String.Empty; result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; //使用代理服务器 if (null == result || result == String.Empty) { result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; } if (null == result || result == String.Empty) { result = HttpContext.Current.Request.UserHostAddress; } return result; }