首页 > 学院 > 开发设计 > 正文

c#获取真实IP和代理IP

2019-11-17 04:27:15
字体:
来源:转载
供稿:网友

获取真实ipview plaincopy to clipboardPRint?
public static string GetRealIP()  
{  
string ip;  
try 
{  
HttpRequest request = HttpContext.Current.Request;  
 
if (request.ServerVariables["HTTP_VIA"] != null)  
{  
ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim();  
}  
else 
{  
ip = request.UserHostAddress;  
}  
}  
catch (Exception e)  
{  
throw e;  
}  
 
return ip;  

public static string GetRealIP()
{
string ip;
try
{
HttpRequest request = HttpContext.Current.Request;

if (request.ServerVariables["HTTP_VIA"] != null)
{
ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim();
}
else
{
ip = request.UserHostAddress;
}
}
catch (Exception e)
{
throw e;
}

return ip;
}获取代理IPview plaincopy to clipboardprint?
public static string GetViaIP()  
{  
string viaIp = null;  
 
try 
{  
HttpRequest request = HttpContext.Current.Request;  
 
if (request.ServerVariables["HTTP_VIA"] != null)  
{  
viaIp = request.UserHostAddress;  
}  
 
}  
catch (Exception e)  
{  
 
throw e;  
}  
 
return viaIp;


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表