asp.net 返回电脑真实IP地址

View Code
1 public static string getIP()
2 {
3 string result = String.Empty;
4 result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
5 if (null == result || result == String.Empty)
6 {
7 result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
8 }
9 if (null == result || result == String.Empty)
10 {
11 result = HttpContext.Current.Request.UserHostAddress;
12 }
13 if (null == result || result == String.Empty)
14 {
15 return "0.0.0.0";
16 }
17 return result;
18 }
posted @ 2011-07-06 14:12  Jack Qin  阅读(295)  评论(1编辑  收藏  举报
作者:Jack Qin http://www.nosqlcn.com