Search code examples
pythontor

How do I get the IP address of the TOR entry node in use


I've been poking around at ways to map tor, and to look at how addresses get allocated but I need to be able to know the IP address of the entry node that I'm using at any given time.

Not really sure where to start as I'm not more than a journeyman programmer (python) and tend to learn bits and pieces as necessary. Any pointers to commands to use would b emuch appreciated.

I did think that running wireshark on an intermediate node might be the easiest way but needs an extra machine that I don't have knocking around at the minute.


Solution

  • Actually, this is very similar to one of our FAQ entries. To get the IP address of your present circuits you can do the following using stem...

    from stem import CircStatus
    from stem.control import Controller
    
    with Controller.from_port() as controller:
      controller.authenticate()
    
      for circ in controller.get_circuits():
        if circ.status != CircStatus.BUILT:
          continue  # skip circuits that aren't yet usable
    
        entry_fingerprint = circ.path[0][0]
        entry_descriptor = controller.get_network_status(entry_fingerprint, None)
    
        if entry_descriptor:
          print "Circuit %s starts with %s" % (circ.id, entry_descriptor.address)
        else:
          print "Unable to determine the address belonging to circuit %s" % circ.id
    

    This provides output like...

    atagar@morrigan:~/Desktop/stem$ python example.py 
    Circiut 15 starts with 209.222.8.196
    Circiut 7 starts with 209.222.8.196
    

    Hope this helps! -Damian