C# 获取客户端IP
2009-07-11 10:44
253 查看
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 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;
}
{
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 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;
}
相关文章推荐
- C# 获取客户端i,客户端主机ip
- [导入]【原】C#里获取客户端IP,端口号的简单示例
- ASP.NET,C#获取客户端IP
- c#中获取服务器IP,客户端IP以及其它
- C#获取客户端IP
- C#中如何获取服务器IP,名称,操作系统,客户端IP,名称!
- c#中获取服务器IP,客户端IP以及Request.ServerVariables详细说明
- C# 获取客户端IP
- c#中获取服务器IP,客户端IP以及Request.ServerVariables详细说明
- [导入]【原】C#里获取客户端IP,端口号的简单示例
- c#获取客户端IP为何得到的值是服务器IP
- c#获取客户端IP
- c#中获取服务器IP,客户端IP以及Request.ServerVariables详细说明
- C#通过Web获取客户端的IP与Mac地址实现
- c#中获取服务器IP,客户端IP以及Request.ServerVariables详细说明
- c#中获取服务器IP,客户端IP以及其它
- c#中获取服务器IP,客户端IP以及其它
- c#中获取服务器IP,客户端IP以及其它
- c# 获取客户端ip、mac、机器名、操作系统、浏览器信息
- C#获得客户端的IP,主机名 获取当前时间