如何找到本机的IP地址? [英] How to find the ip address of local machine?
本文介绍了如何找到本机的IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当前我正在使用以下代码.
Currently i am using below code.
private string GetIP()
{
string strHostName = "";
strHostName = System.Net.Dns.GetHostName();
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
return addr[addr.Length - 1].ToString();
}
在本地工作正常.在直播中,我没有IP地址.
我只得到:: 1..
请帮助我找到正在访问我的网站的用户的IP地址..
谢谢
in local working fine.In live i am not getting ip address.
I just getting ::1 only..
Please help me to find ip address of user who is accessing my site..
Thanks
推荐答案
检查以下链接,这将对您有所帮助.
如何获取机器的IP地址 [^ ]
http://stackoverflow.com/questions/151231/how-do-i-get-the-local-network-ip-address-of-a-computer-programmatically-c [
Hi,
Check the below links, it will helpful for you.
How To Get IP Address Of A Machine[^]
http://stackoverflow.com/questions/151231/how-do-i-get-the-local-network-ip-address-of-a-computer-programmatically-c[^]
尝试一下
string clientIp = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if( !string.IsNullOrEmpty(clientIp) ) {
string[] forwardedIps = clientIp.Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries );
clientIp = forwardedIps[forwardedIps.Length - 1];
} else {
clientIp = context.Request.ServerVariables["REMOTE_ADDR"];
}
http://stackoverflow.com/questions/2670004/ip-address-of-the-客户端计算机 [ ^ ]
http://stackoverflow.com/questions/2670004/ip-address-of-the-client-machine[^]
这篇关于如何找到本机的IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文