如何获取 Tornado 请求的客户端 IP? [英] How do I get the client IP of a Tornado request?

查看:60
本文介绍了如何获取 Tornado 请求的客户端 IP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于传入 post()RequestHandler 对象.如何找到发出请求的客户端的IP?我已经浏览了 RequestHandler 的大部分方法和属性,但似乎遗漏了一些东西.

I have a RequestHandler object for incoming post()s. How can I find the IP of the client making the request? I've browsed most of RequestHandler's methods and properties and seem to have missed something.

推荐答案

RequestHandler.request.remote_ip(来自 RequestHandler 的实例)

RequestHandler.request.remote_ip (from RequestHandler's instance)

您可以像这样检查响应:

you can inspect the response like:

...
class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write(repr(self.request))
...

这篇关于如何获取 Tornado 请求的客户端 IP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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