谁在浏览我的网站的用户的IP地址 [英] IP address of the user who is browsing my website

查看:209
本文介绍了谁在浏览我的网站的用户的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在客户机的IP地址,即谁在浏览我的网站的用户的IP地址。我想下面的代码,但它返回服务器地址 -

 公共字符串GetClientIP()
{
字符串结果=的String.Empty;
串IP = HttpContext.Current.Request.ServerVariables [HTTP_X_FORWARDED_FOR];
如果(!string.IsNullOrEmpty(IP))
{
串[] ipRange = ip.Split(,);
INT乐= ipRange.Length - 1;
结果= ipRange [0];
}
,否则
{
结果= HttpContext.Current.Request.ServerVariables [REMOTE_ADDR];
}

返回结果;
}



我怎样才能找到合适的IP地址?


解决方案

 字符串ip地址=的String.Empty; 
串SearchName =的String.Empty;

字符串strHostName = HttpContext.Current.Request.UserHostAddress.ToString();

ip地址= System.Net.Dns.GetHostAddresses(strHostName).GetValue(0)的ToString();


I want to know the IP address of the client machine, i.e. the IP address of the user who is browsing my website. I am trying the following code but it is returning server address -

public string GetClientIP()
{
    string result = string.Empty;
    string ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
    if (!string.IsNullOrEmpty(ip))
    {
        string[] ipRange = ip.Split(',');
        int le = ipRange.Length - 1;
        result = ipRange[0];
    }
    else
    {
        result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
    }

    return result;
}

How can I find the right IP address?

解决方案

string IPAddress = string.Empty;
string SearchName = string.Empty;

String strHostName = HttpContext.Current.Request.UserHostAddress.ToString();

IPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();

这篇关于谁在浏览我的网站的用户的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆