获取真实IP

 

 1获取真实IP
 2
 3
 4public static string GetRealIP()
 5{
 6string ip;
 7try
 8{
 9HttpRequest request = HttpContext.Current.Request;
10
11if (request.ServerVariables["HTTP_VIA"!= null)
12{
13ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim();
14}

15else
16{
17ip = request.UserHostAddress;
18}

19}

20catch (Exception e)
21{
22throw e;
23}

24
25return ip;
26}

27
28获取代理IP 
29
30public static string GetViaIP()
31{
32string viaIp = null;
33
34try
35{
36HttpRequest request = HttpContext.Current.Request;
37
38if (request.ServerVariables["HTTP_VIA"!= null)
39{
40viaIp = request.UserHostAddress;
41}

42
43}

44catch (Exception e)
45{
46
47throw e;
48}

49
50return viaIp;
posted @ 2008-04-25 16:50  Silent's Blog  阅读(294)  评论(0编辑  收藏  举报