每次获取相同和错误的IP地址集 [英] Getting same and wrong set of IP address everytime

查看:69
本文介绍了每次获取相同和错误的IP地址集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我遇到了一个非常奇怪的问题.我试图获取我的IP地址,但是每当我使用任何方法时,我都会获取此IP地址:127.0.0.1.
我正在使用以下代码:

Hi, I am suffering from a very weird problem. I am trying to get my IP address but every time whatsoever method I make use of I am getting this IP address : 127.0.0.1.
I am using this code:

  string stringIpAddress;
stringIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (stringIpAddress == null) //may be the HTTP_X_FORWARDED_FOR is null
{
stringIpAddress = Request.ServerVariables["REMOTE_ADDR"];//we can use REMOTE_ADDR
}
string strResult =  "Your ip is "+stringIpAddress;



哪里出问题了?请告诉我 ?
我们将不胜感激.



Where am Going wrong ? Please tell me ?
Any help will be appreciated.

推荐答案

您使用的代码用于获取代理服务器或客户端计算机后面的IP地址.
如果要获取IP,则必须尝试以下代码.
The code you have used is for getting the IP Address Behind Proxy Or Client Machine.
If you want to get your IP, you have to try the codes below.
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(1).ToString();


参考-查找IP地址 [ ^ ]
请让我知道它对您有无帮助....

其他链接...
StackOverFlow [ DevCity [编码集群 [


Reference - Find IP Address[^]
Please let me know it helps you or not....

Other links ...
StackOverFlow[^]
DevCity[^]
Codingcluster[^]


这篇关于每次获取相同和错误的IP地址集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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