客户端IP地址跟踪问题 [英] Client IP Address tracking problems

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

问题描述

大家好,

我的系统位于网络中,我的IP地址显示为192.168.1.37(来自系统).现在,如果我使用下面的代码

Hi Everybody,

My system is in a network and my ip Address it is showing 192.168.1.37 (from the system). Now if I use the below code

userid = Convert.ToInt64(SessionManager.LoggedInUserID);
        IPHostEntry host;
        string localIP = "?";
        host = Dns.GetHostEntry(Dns.GetHostName());
        foreach (IPAddress ip in host.AddressList)
        {
            if (ip.AddressFamily.ToString() == "InterNetwork")
            {
                localIP = ip.ToString();
            }
        }



我在本地获得了正确的结果,但在实时运行中,它正在使用服务器IP地址插入客户端IP地址.

但是当我使用以下代码时



I am getting the correct result in local, but in live it is taking the Server Ip address insted of client IP address.

But when I am using the below code

string localIP = Request.UserHostAddress;



对于在两种情况下使用的相同系统,它给出的结果ip为127.0.0.1.但是我还没有把它变成现实.我不知道它是否可以正常工作.但是它(第二个)在本地无法正常工作.

我还需要客户端系统的第一个结果.
任何帮助将不胜感激.



It gives the result ip as 127.0.0.1 for the same system used in both cases. But I have not put it in live. I dont know whether it will work properly or not. But it (2nd one) is not working properly in local.

I need the first result for client system also.
Any help will be appreciated.

推荐答案

我只是在使用cassini(Visual Studio asp.net服务器)时尝试了此操作,结果为127.0.0.1.
当我将其放置在本地IIS上且站点绑定到127.0.0.1时,
结果也是127.0.0.1.
当我将网站绑定到我的计算机名称E51EKGED时,该计算机名称解析为我的真实IP,来自IE的请求结果最终是期望的正确IP I(我想也是).
我现在正在尝试使用FF和Opera来解决这些情况,以确保
这不是一些IE问题.

修改:
深入研究发现它必须是.NET框架的安全功能:
浏览器发送的信息始终相同(标题信息),
但是如果服务器绑定到127.0.0.1,则服务器端代码不允许读取UserHostAddress.
卡西尼(VS WebServer)只能在127.0.0.1(localhost)上侦听请求.这证明了要使用户主机地址返回真实的客户端IP,您必须将解决方案部署到IIS.在我的情况下,此IIS可能位于您的开发计算机上,但该网站必须绑定到除127.0.0.1之外的某些IP.
最终修改

干杯


Manfred
I just tried this and when working with cassini (the visual studio asp.net server) and had 127.0.0.1 as result.
When I put this on my local IIS with the site bound to 127.0.0.1 the
result was also 127.0.0.1.
When I bound the web site to my computer name E51EKGED which resolves to my true IP the result from the request from IE was finally the correct IP I (and you I presume) expected.
I''m now trying these scenarios with FF and Opera just to make sure
it wasn''t some IE issue.

Modification:
Just dug a little deeper and found that it must be a security feature of the .NET framework:
The information sent by the browser is always the same (header info),
but the server side code doesn''t allow the UserHostAddress to be read if the server is bound to 127.0.0.1.
Cassini (VS WebServer) can only listen to requests on 127.0.0.1 (localhost). This proves that to have user host address return the true client IP you''ll have to deploy your solution to an IIS. This IIS as in my case may be on your developing machine, but the web site must be bound to some IP other than 127.0.0.1.
End Modification

Cheers


Manfred


您是否进行日志记录?如果这样做,在您要检查用户的主机地址的地方添加一个调试条目.然后从另一台PC访问您的本地网站,然后查看日志以查看对此进行记录的内容.
但是...理想情况下,您应该分阶段进行部署测试的环境,尤其是要捕获这样的东西.在理想的情况下,您至少要有一个开发服务器,测试服务器,预生产服务器,然后再生产. (如果我错过了要点,请发表评论,我会看看能为您做些什么.:))
Do you do any logging? If you do, add a debug entry where you want to check to user''s host address. Then access your local website from another pc and then check the logs to see what gets logged for this.
However... Ideally, you would have staged environments for deployment testing, specifically to catch stuff like this. In a perfect world, you would have at minimum a development server, test server, pre-prod server, and then production. (If I''m missing the point please comment, and I''ll see what I can do to help. :) )


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

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