tornado获取客户端IP

网上搜到的用tornado获取客户端IP都使用self.request.headers['X-Real-Ip'],但实际翻tornado源代码发现只需要获取self.request.remote_ip即可取到客户端IP

见引用tornado源代码(对应文件为httpserver.py中HTTPRequest属性remote_ip)

if connection and connection.xheaders:

# Squid uses X-Forwarded-For, others use X-Real-Ip

self.remote_ip = self.headers.get(

"X-Real-Ip", self.headers.get("X-Forwarded-For", remote_ip))

# AWS uses X-Forwarded-Proto

self.protocol = self.headers.get(

"X-Scheme", self.headers.get("X-Forwarded-Proto", protocol))

if self.protocol not in ("http", "https"):

self.protocol = "http"

else:

self.remote_ip = remote_ip

if protocol:

self.protocol = protocol

elif connection and isinstance(connection.stream,

iostream.SSLIOStream):

self.protocol = "https"

else:

self.protocol = "http"

已有21条评论 »

  1. Viagra cialis without prescription us for sale,viagra cialis generic,viagra cialis india - Online (/index.

  2. Viagra vs on line india cialis discount I take Cialis regardless on both empty and full stomachs and it works for me.

  3. Thank you for every other informative blog. The place else may just I get that type of info written in such a perfect means? I've a project that I'm just now working on, and I have been at the glance out for such information.

  4. Thank you for every other informative blog. The place else may just I get that type of info written in such a perfect means? I've a project that I'm just now working on, and I have been at the glance out for such information.

  5. And cheap levitra only left http://indian10via.com/ for rather mellows with?

  6. Simplest method is qual o nome do medicamento generico do buy viagra online for for multiple body which thin.

  7. Generic buy viagra online works from these a viagra for women of tubes along with veins.

  8. I just like the valuable info you provide in your articles. I will bookmark your weblog and check once more here frequently. I am moderately sure I will be told lots of new stuff right right here! Best of luck for the following!

  9. I just like the valuable info you provide in your articles. I will bookmark your weblog and check once more here frequently. I am moderately sure I will be told lots of new stuff right right here! Best of luck for the following!

  10. for

    viagra for sale without a prescription For Sale In Usa Stores With Next Day Delivery in Texas City .

  11. Low price of brand generic photos viagra for ED patients.

  12. photos viagra, he has delegated to head of his toddler, both are your last year old guys for red.

  13. is elocon a steroid cream

  14. is elocon a steroid cream

  15. Where to get free viagra samples, what is the best online pharmacy for viagra .

  16. Albert n/a Will free viagra Work for Everyone?

  17. free viagra For Sale In Usa Stores With Next Day Delivery in Rowlett .

  18. et

    博主估计看错了,或者tornado升级了

  19. bitwolaiye

    我试了反向代理时,self.request.remote_ip是‘127.0.0.1’self.request.headers['X-Real-Ip']是真是地址

  20. 代码里已经有对于X-Real-Ip的判断了,直接self.request.remote_ip就足够了

添加新评论 »