如何查找运行网站的客户端IP地址 [英] How find Client IP Address on which the Website is running

查看:138
本文介绍了如何查找运行网站的客户端IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我需要获取运行我网站的客户端IP地址,我已尝试过以下代码,



Hi All,

I have a need to get the Client IPAddress on which my Website is running, I have tried the Following Code,

string ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
System.Net.IPAddress ip = default(System.Net.IPAddress);
ip = new System.Net.IPAddress(System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList[0].Address);
string ip1 = Request.UserHostAddress;
string ipMethod1 = HttpContext.Current.Request.UserHostAddress;
txtID.Text = ip1.ToString() + "---" + ipMethod1.ToString();





当我的项目在IIS中运行时工作正常,在Server中托管代码后,代码只返回Server IP地址,请帮我这个



先谢谢。



It is working fine when my project is running in IIS, after hosting the code in Server the code returns only Server IP Address, Please help me in this

Thanks in Advance.

推荐答案

试试:

Try:
Request.ServerVariables("REMOTE_ADDR")






or

Request.UserHostAddress






or

Request.ServerVariables("HTTP_X_FORWARDED_FOR")





--Amit



--Amit


尝试使用Request.UserHostAddress



Request.UserHostName

以及

您可以使用客户端脚本获取COmputerName但是我警告你,activex是有害的



< pre lang =cs> var net = new ActiveXObject(& quot; wscript.network& quot;);

alert(net.ComputerName)< / pre>



else

如果用户登录代理服务器你也可以用

str = Request.Servervariables [HTTP_X_FORWARDEDFOR]

如果str =

str = Request.Servervariables [REMOTE_ADDR]

结束如果

IN ACtual客户端实际IP地址不可能
Try with Request.UserHostAddress
and
Request.UserHostName
and also
you can use Client script to get COmputerName but i warn u activex is harmful

<pre lang="cs">var net = new ActiveXObject(&quot;wscript.network&quot;);
alert(net.ComputerName)</pre>

else
if user is logged on from Proxy server you can also check
with
str=Request.Servervariables["HTTP_X_FORWARDEDFOR"]
If str=""
str=Request.Servervariables["REMOTE_ADDR"]
end if
IN ACtual Client REAL IP ADDRESS GETTING IS NOT POSSIBLE


下面的代码将帮助你获取客户机IP地址



below code will help u to get client machine IP Address

public string getipaddress()
    {
        string ipaddress;

        ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

        if (ipaddress == "" || ipaddress == null)

            ipaddress = Request.ServerVariables["REMOTE_ADDR"];

        return ipaddress;
    }


这篇关于如何查找运行网站的客户端IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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