I just start to use tor controller, I notice the mannual says:
pass Tor the "--CookieAuthentication 1" option when you start it. Tor will create a file in its data directory called "control_auth_cookie". All your controller needs to do is to pass the contents of this file to authenticate() when it connects to Tor.
there are two kinds of Tor, one is installed and can be run by command "tor" the other is Tor Browser Bundle,
1) with command "tor", when it establishes, if I run example.py the result is "Connection refused. Is the ControlPort enabled?"
I tried command: "tor --CookieAuthentication 1" to start Tor, but I can't find the so called data directory, and the running information says: Could not open "/etc/tor/torrc": Permission denied
2) with TBB, after I started TBB, if I run example.py, it seems it can connect to ControlPort, but it prompts for a password there is a Data directory in TBB, but I can't find the so called " control_auth_cookie" file, so when I run TBB, how can I pass "--CookieAuthentication 1" to tor?
example.py :
import time import TorCtl
class BandwidthListener(TorCtl.PostEventListener): def __init__(self): TorCtl.PostEventListener.__init__(self)
def bandwidth_event(self, event): print "tor read %i bytes and wrote %i bytes" % (event.read, event.written)
# constructs a listener that prints BW events myListener = BandwidthListener()
# initiates a TorCtl connection, returning None if it was unsuccessful conn = TorCtl.connect()
if conn: # tells tor to send us BW events conn.set_events(["BW"])
# attaches the listener so it'll receive BW events conn.add_event_listener(myListener)
# run until we get a keyboard interrupt try: while True: time.sleep(10) except KeyboardInterrupt: pass
Hi Jiang. First, TorCtl is being deprecated by two newer (more actively developed) controller libraries...
Stem (https://stem.readthedocs.org/en/latest/) - Threaded library with a similar design to TorCtl. Txtorcon (https://txtorcon.readthedocs.org/en/latest/) - Twisted based controller library.
Please try one of those. Here's a tutorial that should help you with getting started...
https://stem.readthedocs.org/en/latest/tutorial.html#the-little-relay-that-c...
- with command "tor", when it establishes, if I run example.py
the result is "Connection refused. Is the ControlPort enabled?"
Maybe the browser bundle uses a non-standard port or a control socket? By default TorCtl and Stem look for 9051 since that's the default control port by convention. The browser bundle pops up an instance of Vidalia and you can look in its settings for the details of how it connects to Tor.
Simplest solution is to not use the browser bundle at all, and instead make a text file with...
ControlPort 9051 CookieAuthentication 1
... then start Tor with "tor -f /path/to/that/file". The example you're running should then work.
Cheers! -Damian