Monday, May 30, 2011

How to “flush tor circuit”

tor already switches the route roughly every 10 minutes. Sometimes you may need to get new tor ip or new route programatically. Here is how to do it in ruby.


What we are doing is "Send a SIGHUP to Tor. According to its man page this should make Tor fetch a new directory".
We can send a SIGHUP to tor get new route, thus a new tor ip.



require 'rubygems'
require 'sys/proctable' 
include Sys



  Sys::ProcTable.ps.each { |ps|
    if ps.name.downcase == "tor"      
      Process.kill('SIGHUP', ps.pid)
    end
  }

you can schedule this script to run periodically, say every 1 minutes. Then you will be getting new tor ip every minutes.


https://svn.torproject.org/svn/incognito/trunk/root_overlay/etc/NetworkManager/dispatcher.d/50-tor-sighup.sh

No comments:

Post a Comment