我如何从HTTP_X_FORWARDED_FOR正确的IP,如果它包含多个IP地址? [英] How do I get the correct IP from HTTP_X_FORWARDED_FOR if it contains multiple IP Addresses?

查看:1427
本文介绍了我如何从HTTP_X_FORWARDED_FOR正确的IP,如果它包含多个IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果Request.ServerVariables [HTTP_X_FORWARDED_FOR]返回多个IP的,哪一个我需要和我将如何做它在C#中?这是我的理解是,如果它是空白或空,然后在客户端计算机不会通过代理,我可以刚刚从Request.ServerVariables [REMOTE_ADDR]获取IP。这是一个正确的语句?

If Request.ServerVariables["HTTP_X_FORWARDED_FOR"] returns multiple ip's, which one do I take and how would I do it in c#? It is my understanding that if it is blank or null, then the client computer is not going through a proxy and I can just get their ip from Request.ServerVariables["REMOTE_ADDR"]. Is this a correct statement?

通过哪一个呢我走,我的意思是我采取的第一个IP列表或最后一个IP是我必须要做的仅仅是将它分成数组,并采取一个我想要的。我真的不知道HTTP_X_FORWARDED_FOR是如何工作的。

By "which one do I take", I mean do I take the first IP in the list or the last IP and is all I have to do is just split it into an array and take the one I want. I am not really sure how HTTP_X_FORWARDED_FOR works.

推荐答案

根据这个中,第X - 转发,对于HTTP标头的格式是:

According to this, the format of X-Forwarded-For HTTP header is:

X-Forwarded-For: client1, proxy1, proxy2, ...

所以,你希望客户端的IP地址应该在列表中的第一个

So the IP address of the client that you want should be the first one in the list

这篇关于我如何从HTTP_X_FORWARDED_FOR正确的IP,如果它包含多个IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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