获取真实IP
1
获取真实IP
2
3
4
public static string GetRealIP()
5
{
6
string ip;
7
try
8
{
9
HttpRequest request = HttpContext.Current.Request;
10
11
if (request.ServerVariables["HTTP_VIA"] != null)
12
{
13
ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim();
14
}
15
else
16
{
17
ip = request.UserHostAddress;
18
}
19
}
20
catch (Exception e)
21
{
22
throw e;
23
}
24
25
return ip;
26
}
27
28
获取代理IP
29
30
public static string GetViaIP()
31
{
32
string viaIp = null;
33
34
try
35
{
36
HttpRequest request = HttpContext.Current.Request;
37
38
if (request.ServerVariables["HTTP_VIA"] != null)
39
{
40
viaIp = request.UserHostAddress;
41
}
42
43
}
44
catch (Exception e)
45
{
46
47
throw e;
48
}
49
50
return viaIp;
获取真实IP2

3

4
public static string GetRealIP()5
{6
string ip;7
try8
{9
HttpRequest request = HttpContext.Current.Request;10

11
if (request.ServerVariables["HTTP_VIA"] != null)12
{13
ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim();14
}15
else16
{17
ip = request.UserHostAddress;18
}19
}20
catch (Exception e)21
{22
throw e;23
}24

25
return ip;26
}27

28
获取代理IP 29

30
public static string GetViaIP()31
{32
string viaIp = null;33

34
try35
{36
HttpRequest request = HttpContext.Current.Request;37

38
if (request.ServerVariables["HTTP_VIA"] != null)39
{40
viaIp = request.UserHostAddress;41
}42

43
}44
catch (Exception e)45
{46

47
throw e;48
}49

50
return viaIp;




浙公网安备 33010602011771号