2

我已经建立了一个 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()

谢谢!

4

2 回答 2

0

您对 stem 的使用看起来是正确的,但如果您将其扩展为执行多个数据点,您可能希望查看BW 事件。至于 web.py,他们网站上的示例返回一个 view.render.base 实例,也许这是缺少的部分?

于 2013-07-04T17:57:36.263 回答
0

好吧,我现在开始工作了。尴尬,但似乎我做错的只是忘记了密码周围的引号。我还在上课前将 app = web.application(urls, globals()) 向上移动。如果它有所作为,现在不要。现在,关于带宽事件,以制作带有统计信息的实时更新网页。

于 2013-07-04T19:56:33.507 回答