-
-
Save pragma31/fc4c2b472cb5234a4c4a10f8b499b7d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from stem.control import Controller, EventType | |
from stem import StreamStatus | |
import functools | |
# using stem 1.8.0 | |
TORBROWSER_CTRL = 9151 | |
def stream_event(controller, event): | |
if event.status == StreamStatus.SUCCEEDED and event.circ_id: | |
circ = controller.get_circuit(event.circ_id) | |
exit_fingerprint = circ.path[-1][0] | |
exit_relay = controller.get_network_status(exit_fingerprint) | |
print("Exit relay for our connection to %s" % (event.target)) | |
print(" address: %s:%i" % (exit_relay.address, exit_relay.or_port)) | |
print(" fingerprint: %s" % exit_relay.fingerprint) | |
print(" nickname: %s" % exit_relay.nickname) | |
print(" locale: %s" % controller.get_info("ip-to-country/%s" % exit_relay.address, 'unknown')) | |
print('stream purpose', event.purpose) | |
print('circuit purpose', circ.purpose) | |
print('circuit flags', circ.build_flags) | |
if len(circ.path) == 1: | |
print('single hop!') | |
print() | |
def main(): | |
''' | |
assumed: torbrowser is running | |
''' | |
with Controller.from_port(port=TORBROWSER_CTRL) as controller: | |
controller.authenticate() | |
print('connected - Tor version :', controller.get_version(), '\n') | |
stream_listener = functools.partial(stream_event, controller) | |
controller.add_event_listener(stream_listener, EventType.STREAM) | |
while True: | |
pass | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
filtering out with IS_INTERNAL :
--- some numbers ---
a 25 minutes browsing session in torbrowser, using up to 5 tabs, asking for a new identity twice :
got 955 events, every one of them showed :