class TorProtocol::Tor
Public Class Methods
new(control_port='9051',socks_port='9050')
click to toggle source
debug Socksify::debug = true
# File lib/instabot/tor_protocol.rb, line 7 def initialize(control_port='9051',socks_port='9050') puts '[+] '.cyan + "[TOR] STARTED" @tor_control_port = control_port @tor_socks_port = socks_port TCPSocket::socks_server = "127.0.0.1" TCPSocket::socks_port = @tor_socks_port puts '[+] '.cyan + "[TOR] current ip [#{current_ip.yellow}]" end
Public Instance Methods
current_ip()
click to toggle source
# File lib/instabot/tor_protocol.rb, line 16 def current_ip a = Mechanize.new a.user_agent_alias = 'Mac Safari' return a.get('http://www.myexternalip.com/raw').body.chomp rescue Exception => e puts "error getting ip: #{e.class} #{e.message}\n#{e.backtrace.inspect}".red # break # puts "An error occured ... #{e.class} #{e.message}\n#{e.backtrace.inspect}\n[ignored]" end
get_new_ip()
click to toggle source
# File lib/instabot/tor_protocol.rb, line 26 def get_new_ip puts '[+] '.cyan + "[TOR] trying to get a new ip address.." old_ip_address = current_ip tor_switch_endpoint sleep 10 new_ip_address = current_ip if (old_ip_address != new_ip_address) puts '[+] '.cyan + "[TOR] ip changed from [#{old_ip_address.yellow}] to [#{new_ip_address.yellow}]" return true else puts '[+] '.yellow + "[TOR] ip same [#{old_ip_address}]" get_new_ip end end
tor_switch_endpoint()
click to toggle source
# File lib/instabot/tor_protocol.rb, line 41 def tor_switch_endpoint # puts "tor_switch_endpoint.." tor_protocol = Net::Telnet::new("Host" => "localhost", "Port" => "#{@tor_control_port}", "Timeout" => 10, "Prompt" => /250 OK\n/) tor_protocol.cmd('AUTHENTICATE ""') { |c| throw "Cannot authenticate to Tor" if c != "250 OK\n" } tor_protocol.cmd('signal NEWNYM') { |c| throw "Cannot switch Tor to new route" if c != "250 OK\n" } tor_protocol.close end