【问题标题】:Getting Tor Control data through Stem and presenting on the web with web.py通过 Stem 获取 Tor Control 数据并使用 web.py 在网络上呈现
【发布时间】:2013-07-01 08:35:26
【问题描述】:

我已经设置了一个 Tor 中继,并希望它在网页上显示一些关于自身的统计信息。因此我在同一个盒子上安装了 lighttpd 和 web.py 并且运行良好。

我还安装了 Stem,我可以使用此处找到的 Python 示例成功地从 Tor 控制端口获取数据:https://stem.torproject.org/tutorials/the_little_relay_that_could.html

现在我想将两者结合起来,让 web.py 运行脚本并将数据输出到网站。我已经摆弄了几个小时,但我没有线索。我需要如何编写 python web.py 应用程序?这是一个不起作用的尝试示例:

import web
from stem.control import Controller

urls = (
    '/', 'index'
)

class index:
    def GET(self):
        with Controller.from_port(port = 9051) as controller:
            controller.authenticate("mypassword")  # provide the password here if you set one

            bytes_read = controller.get_info("traffic/read")
            bytes_written = controller.get_info("traffic/written")

            return "My Tor relay has read %s bytes and written %s." % (bytes_read, bytes_written)

if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()

谢谢!

【问题讨论】:

    标签: python web.py tor


    【解决方案1】:

    如果您将其扩展为执行多个数据点,您可能希望查看BW events,但您对 stem 的使用看起来是正确的。至于 web.py,examples on their site 返回一个 view.render.base 实例,可能是缺少的那一点?

    【讨论】:

    • 感谢您的回答。显然我只是忘记了密码周围的引号...... :) 我肯定会扩展它,并研究 Stem 的更高级功能。你是作者,对吧?谢谢你!
    • 是的。我很高兴也很高兴你喜欢它!
    【解决方案2】:

    嗯,我现在开始工作了。尴尬,但似乎我做错的只是忘记了密码周围的引号。我也搬了 app = web.application(urls, globals()) 上课前起来。如果它有所作为,现在不要。现在,开始使用带宽事件来制作带有统计信息的实时更新网页。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-22
      • 1970-01-01
      • 2015-09-22
      相关资源
      最近更新 更多