如何获得客户端机器的确切IP地址? [英] How to get exact ip address of client machin?

查看:163
本文介绍了如何获得客户端机器的确切IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道REMOTE_ADDR返回路由器的IP地址,而不是客户端用户的机器。 HTTP_X_FORWARDED_FOR,因为当客户端用户在代理服务器后面时,他的机器的IP地址将代理服务器的IP地址附加到客户端机器的IP地址。如果客户端机器在许多代理服务器后面,则所有服务器ID都附加到它。但我只想要客户机器地址。如何获得?



string ipaddress;

ipaddress = Request.ServerVariables [HTTP_X_FORWARDED_FOR];

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

ipaddress = Request.ServerVariables [REMOTE_ADDR];



我尝试过:



string ipaddress;

ipaddress = Request.ServerVariables [ HTTP_X_FORWARDED_FOR];

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

ipaddress = Request.ServerVariables [REMOTE_ADDR];

I know REMOTE_ADDR returns the IP Address of the router and not the client user’s machine. HTTP_X_FORWARDED_FOR, since when client user is behind a proxy server his machine’s IP Address the Proxy Server’s IP Address is appended to the client machine’s IP Address.If client machine is behind many proxy server,all server id is appended to it.But I want only client machin address.How to get that?

string ipaddress;
ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (ipaddress == "" || ipaddress == null)
ipaddress = Request.ServerVariables["REMOTE_ADDR"];

What I have tried:

string ipaddress;
ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (ipaddress == "" || ipaddress == null)
ipaddress = Request.ServerVariables["REMOTE_ADDR"];

推荐答案

基本上,你不能:实际的客户端机器IP地址不会转移到路由器之外,因为它会几乎可以肯定的是192.168.0.xxx的形式 - 使用的是连接到互联网的点的IP地址 - 通常是路由器 - 并且由该点连接的所有用户共享。



使用代理,情况更糟,因为并非所有代理都会将HTTP_X_FORWARDED_FOR设置为客户端IP - 这就是代理的想法,它完全剥离ID信息,并通过它自己的IP传递请求然后在内部翻译以将响应传递给原始客户端。



很可能,你无法得到你想要的在所有情况下。
Basically speaking, you can't: the actual client machine IP address is not transferred beyond the router as it will almost certainly be of the form 192.168.0.xxx - what is used is the IP address of the point of connection to the internet - usually the router - and that is shared by all users of that point of connection.

With proxies, it's even worse, because not all proxies will set the HTTP_X_FORWARDED_FOR to the client IP - that's kind of the idea of a proxy, that it "strips out" the ID info completely, and passes the requests via it's own IP then "translates back" internally to pass the response to the original client.

In all probability, you cannot get what you want in all cases.


这是一个非常常见的问题,如果你在搜索之前用Google搜索,你会很容易找到答案,这是你不能的。你想要它或者需要它不会改变这个事实,它只是互联网的运作方式。
This is a very frequently asked question, if you googled before asking you would have easily found the answer, which is that you can't. You wanting it or needing it won't change that fact, it's just how the internet works.


这篇关于如何获得客户端机器的确切IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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