Skip to content

Instantly share code, notes, and snippets.

@evilaliv3
Created February 17, 2017 10:37
Show Gist options
  • Save evilaliv3/ca3d5495694a72b4f024a3eaf2f490f5 to your computer and use it in GitHub Desktop.
Save evilaliv3/ca3d5495694a72b4f024a3eaf2f490f5 to your computer and use it in GitHub Desktop.
get tor exit list using txtorcon
#!/usr/bin/env python
from sys import stdout
from twisted.internet import reactor
from twisted.internet.endpoints import TCP4ClientEndpoint
from twisted.internet.task import react, LoopingCall
from twisted.internet.defer import inlineCallbacks
import txtorcon
@inlineCallbacks
def main(reactor):
config = txtorcon.TorConfig()
config.OrPort = 0 # could set this to be a relay, e.g. 1234
config.SocksPort = [9999]
yield txtorcon.launch_tor(config, reactor, stdout=stdout)
proto = config.protocol
state = yield txtorcon.TorState.from_protocol(proto)
@inlineCallbacks
def runEverySecond():
state = yield txtorcon.TorState.from_protocol(proto)
print [r for r in state.routers.values() if 'exit' in r.flags]
yield LoopingCall(runEverySecond).start(5.0) # call every 5 second
if __name__ == '__main__':
react(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment