如何获得在ASP.NET用户的客户端IP地址? [英] How to get a user's client IP address in ASP.NET?

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

问题描述

我们有 Request.UserHostAddress 来获得ASP.NET中的IP地址,但是这通常是用户的ISP的IP地址,不完全是在用户的机器的IP地址为谁例如点击一个链接。我怎样才能得到真正的IP地址?

We have Request.UserHostAddress to get the IP address in ASP.NET, but this is usually the user's ISP's IP address, not exactly the user's machine IP address who for example clicked a link. How can I get the real IP Address?

例如,在一个堆栈溢出用户配置文件,它是:上次帐户活动:4小时前来自86.123.127.8,但我的机器的IP地址是一个有点不同。如何堆栈溢出得到这个地址吗?

For example, in a Stack Overflow user profile it is: "Last account activity: 4 hours ago from 86.123.127.8", but my machine IP address is a bit different. How does Stack Overflow get this address?

在某些网站系统有一些目的IP地址检查。例如,某个IP地址,每24小时可以将用户只需要5只下载链接的点击?这个IP地址应该是唯一的,而不是有一个巨大的客户端或互联网用户范围内的ISP。

In some web systems there is an IP address check for some purposes. For example, with a certain IP address, for every 24 hours can the user just have only 5 clicks on download links? This IP address should be unique, not for an ISP that has a huge range of clients or Internet users.

我才明白呢?

推荐答案

正如其他人说你不能做你的要求。如果你描述的问题,您正在试图解决也许有人可以帮忙吗?例如。你想唯一识别你的用户?你可以使用一个Cookie,或会话ID可能代替IP地址的?

As others have said you can't do what you are asking. If you describe the problem you are trying to solve maybe someone can help? E.g. are you trying to uniquely identify your users? Could you use a cookie, or the session ID perhaps instead of the IP address?

修改在服务器上看到的地址不应该是ISP的地址,因为你说,将是一个巨大的范围。的地址上宽带家庭用户将在他们的路由器的地址,所以在屋内的每个设备将出现在外面是相同的,但是路由器使用NAT来确保交通正确地路由到每个设备。对于用户办公环境中访问该地址可能是对所有用户都是相同的。对于ID使用IP地址的网站上运行得到它非常错误的风险 - 你给的例子是好的,他们往往会失败。例如我的办公室是在英国,突破点(其中I看起来是在互联网上)是在另一个国家,我们主要的IT设施,所以从我的办公室,我的IP地址,看起来是不是在英国。出于这个原因,我不能访问英国唯一的网络内容,如BBC的iPlayer(和我的雇主大概是这个:-)很高兴)。在任何给定的时间会有数百甚至数千人在我的公司谁似乎是从同一个IP地址访问网络。

Edit The address you see on the server shouldn't be the ISP's address, as you say that would be a huge range. The address for a home user on broadband will be the address at their router, so every device inside the house will appear on the outside to be the same, but the router uses NAT to ensure that traffic is routed to each device correctly. For users accessing from an office environment the address may well be the same for all users. Sites that use IP address for ID run the risk of getting it very wrong - the examples you give are good ones and they often fail. For example my office is in the UK, the breakout point (where I "appear" to be on the internet) is in another country where our main IT facility is, so from my office my IP address appears to be not in the UK. For this reason I can't access UK only web content, such as the BBC iPlayer (and my employer is probably very happy about this:-) ). AT any given time there would be hundreds, or even thousands of people at my company who appear to be accessing the web from the same IP address.

当你写服务器code,你不能确定你所看到的IP地址就像是它的一些用户这样闯民宅to.In事实。有人故意使用annoymising代理,以进一步惩罚你,出于安全或隐私原因,他们的路线是通过代理的网络流量,使你不会知道谁或该用户。

When you are writing server code you can never be sure what the IP address you see is refering to.In fact some users like it this way. Some people deliberately use an annoymising proxy to further confound you, for security or privacy reasons they route their web traffic via a proxy so that you won't know who or where that user is.

当你说你的机器的地址是在计算器上显示的IP地址不同,你如何找出你的机器地址?如果你只是寻找本地使用 IPCONFIG 或类似的东西,我会想到它是因为我上面提到的原因不同。如果要仔细检查一下外界认为看看 whatismyipaddress.com/

When you say your machine address is different to the IP address shown on StackOverflow, how are you finding out your machine address? If you are just looking locally using ipconfig or something like that I would expect it to be different for the reasons I outlined above. If you want to double check what the outside world thinks have a look at whatismyipaddress.com/.

在此NAT 维基百科的链接将为您提供一些这方面的背景。

This Wikipedia link on NAT will provide you some background on this.

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

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