如何从用户登录的地方获取IP地址? [英] How to fetch Ip address from where user logged in?
本文介绍了如何从用户登录的地方获取IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何获取IP地址..
用户登录的地方.
我想将其保存在数据库中.
Hi,
I want to know that how to fetch the IP ADDRESS..
from where user logged in.
And i wants to save it in database.
推荐答案
如果可以通过Internet访问您的应用程序,则获取IP地址可能没有任何意义,但是您可以尝试以下操作:
If your application is accessible over the internet then getting the IP address may not make any sense but you can try the following:
HttpContext.Current.Request.UserHostAddress;
or
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
尝试一下
IPHostEntry GetIPHost = Dns.GetHostEntry(Request.UserHostName);
if (GetIPHost != null)
ip = GetIPHost.AddressList[0].ToString();
并参考
http://alperguc.blogspot.in/2008/11/c-how-to-get-computer-ip-address.html [ ^ ]
and also refere
http://alperguc.blogspot.in/2008/11/c-how-to-get-computer-ip-address.html[^]
这篇关于如何从用户登录的地方获取IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文