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