如何获取正在从中访问网站的计算机的IP. [英] How to fetch IP of a machine from which website is being accessed.

查看:191
本文介绍了如何获取正在从中访问网站的计算机的IP.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

我必须在我要访问其网站的网站上向用户显示计算机IP.就像在way2sms.com网站上从哪个IP访问您的IP一样,它表明您已从该IP登录.

是否有相同的任何Web服务.请让我知道.

谢谢

Varun Sareen

Dear Friends,

I have to show the user Machine IP on my website from which they are accessing the Website. Like in way2sms.com website from which IP your are accessing the website it shows that you are logged on from this IP.

Is there any web-service for the same. Please let me know.

Thanks

Varun Sareen

推荐答案

此处:
Here: http://bytes.com/topic/asp-classic/answers/439176-how-get-clients-ip-address-asp-net[^].

—SA


您可以使用Request.ServerVariables["REMOTE_ADDR"]获取客户端/用户计算机的IP地址.

看看下面的链接,了解更多Request.ServerVariables.

http://www.w3schools.com/asp/coll_servervariables.asp
You may use Request.ServerVariables["REMOTE_ADDR"] to get IP address of the Client/Users machine.

Have a look at below link for more Request.ServerVariables.

http://www.w3schools.com/asp/coll_servervariables.asp


public static 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;
}





If u run u will get the ip address 127.0.0.1.Here 127.0.0.1 is localhost. this means you are working on your PC. If you try other PC to use your app, you will get a different ip address.what i mean is host your application in your IIS or on your server and another pc must use your application. with that, you will get a different IP. 127.0.0.1 is localhost, meaning, current IP address.


这篇关于如何获取正在从中访问网站的计算机的IP.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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