How to get visitor IP on load balancing machine us

2019-03-21 11:05发布

We are having two load balancing server. In that we have hosted a asp.net 3.5 application right now we are using request userhostaddress to get visitor ip but it is giving load balancer ip instead of real ip. Can anyone have code for this.

3条回答
一夜七次
2楼-- · 2019-03-21 11:21

I think that you must search not only for HTTP_X_FORWARDED_FOR, but for all that, depent what your loading ballance using

Context.Request.ServerVariables[CheckAllBelowList]

"HTTP_X_COMING_FROM",
"HTTP_X_FORWARDED_FOR",
"HTTP_X_FORWARDED",
"HTTP_VIA",
"HTTP_COMING_FROM",
"HTTP_FORWARDED_FOR",
"HTTP_FORWARDED",
"HTTP_FROM",
"HTTP_PROXY_CONNECTION",
"HTTP_CLIENT_IP",
"CLIENT_IP",
"FORWARDED",

The return of one of that, is the actual Ip of you client, except if is other proxy, I also need to learn how some one can get this, to find the user that is behind 2-3 proxy's...

If you know any other, please tell me so.

查看更多
成全新的幸福
3楼-- · 2019-03-21 11:24

depending on the load balancing server the client's IP could/should be written to:

Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

But beware if the user is also behind a proxy the value may be the proxies original client instead of the load balancer's client (which would be the proxy IP in this case). I'm not certain what behaviour is "normal".

Hope that helps, Alex

查看更多
爷的心禁止访问
4楼-- · 2019-03-21 11:33

The problem is more to do with the fact that the "load balancer" is acting as a proxy. What type of load balancer are you using? I know with Microsoft ISA server there is a setting to pass the original users IP address through to the webserver.

Otherwise you will have to write a page to dump out the server variables and see if there an extra server variable being added that gives you the real client IP address.

查看更多
登录 后发表回答