如何获取客户端IP地址 [英] How to get client ip address

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

问题描述

HI全部



当我在本地主机上运行我的asp.net网络应用程序时,我可以获得本地系统IP地址



i我的结果为IP地址::: 1是否正确





谢谢提前

HI all

can i get the local system ip address when i am running my asp.net web application on local host

i am getting my result as "IP Address: ::1" is it correct or not


thank's in advance

推荐答案

请看我对这个问题的评论。您可以使用 Request.UserHostAddress

http://msdn.microsoft.com/en-us/library/system.web.httprequest.userhostaddress.aspx [ ^ ]



Request.ServerVariables(REMOTE_ADDR)

http://msdn.microsoft.com/en-us/library/system.web.httprequest.servervariables.aspx [<一个href =http://msdn.microsoft.com/en-us/library/system.web.httprequest.servervariables.aspxtarget =_ blanktitle =New Window> ^ ]。br这是IIS的列表:

http://msdn.microsoft.com/en-us/library/ms524602.aspx [ ^ ]。



-SA
Please see my comment to the question. You can use Request.UserHostAddress:
http://msdn.microsoft.com/en-us/library/system.web.httprequest.userhostaddress.aspx[^]

or Request.ServerVariables("REMOTE_ADDR"):
http://msdn.microsoft.com/en-us/library/system.web.httprequest.servervariables.aspx[^].

This is the list for IIS:
http://msdn.microsoft.com/en-us/library/ms524602.aspx[^].

—SA


如果您尝试从localhost运行应用程序时获取ip,您将获得如上所述的127.0.0.1之类的内容。请看下面的内容代码。



If you try to get ip while running application from localhost you will get something like 127.0.0.1 as said by the experts above.Have a look at the below code.

string ip=Server.HtmlEncode(Request.UserHostAddress);





这行代码在localhost上执行时会给你类似127.0.0.1的内容。但是假设你主持它生产服务器,那时它将为您提供实际的客户端IP(字符串格式),即尝试与您的网络交互等。



This line of code,when executed on localhost,will give you something like 127.0.0.1.But suppose you host it on production server,at that time it will give you the actual client ip(in string format),that is the one trying to interact with your web etc.


http://forums.asp.net/t/1829963.aspx/1 [ ^ ]





http://stackoverflow.com/questions/9309769/asp-net-getting-server-local-ip [ ^ ]


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

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