2016-09-12 4 views
8

मैं रेल 4.2.7 का उपयोग कर रहा हूं और मेरे पास कई टोर रत्न स्थापित हैं।रुबी/टोर का उपयोग करके मैं अपना आईपी पता कैसे बदलूं?

gem 'tor' 
gem 'tor_requests' 
gem 'tor-privoxy' 
gem 'net-telnet' 

मैं अपने टो ब्राउज़र (मैक एल कैप्टन पर चल रहा है) शुरू कर दिया और मैं समय-समय पर (हर 20 वीं अनुरोध) जहाँ मेरे टीओआर वेब अनुरोध उत्पन्न का IP पता बदलना चाहते हैं। इसलिए मैंने इस

agent = TorPrivoxy::Agent.new '127.0.0.1', '', {8118 => 9151} do |agent| 
    sleep 1 
    puts "New IP is #{agent.ip}" 
end 

हालांकि, यह निम्न त्रुटि में परिणाम देता है। मैं उलझन में हूं कि मुझे चीजों को कॉन्फ़िगर करने की आवश्यकता है ताकि मैं उपरोक्त काम कर सकूं।

Error during processing: Failed to open TCP connection to 127.0.0.1:8118 (general SOCKS server failure) 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:882:in `rescue in block in connect' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:879:in `block in connect' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/timeout.rb:101:in `timeout' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:878:in `connect' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:863:in `do_start' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:858:in `start' 
/Users/davea/.rvm/gems/ruby-2.3.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:700:in `start' 
/Users/davea/.rvm/gems/ruby-2.3.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:631:in `connection_for' 
/Users/davea/.rvm/gems/ruby-2.3.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:994:in `request' 
/Users/davea/.rvm/gems/ruby-2.3.0/gems/mechanize-2.7.5/lib/mechanize/http/agent.rb:274:in `fetch' 
/Users/davea/.rvm/gems/ruby-2.3.0/gems/mechanize-2.7.5/lib/mechanize.rb:464:in `get' 
/Users/davea/.rvm/gems/ruby-2.3.0/gems/tor-privoxy-0.1.1/lib/tor-privoxy/agent.rb:38:in `ip' 
/Users/davea/Documents/workspace/myproject/app/helpers/webpage_helper.rb:57:in `block in get_content' 
/Users/davea/.rvm/gems/ruby-2.3.0/gems/tor-privoxy-0.1.1/lib/tor-privoxy/agent.rb:11:in `initialize' 
/Users/davea/Documents/workspace/myproject/app/helpers/webpage_helper.rb:55:in `new' 
/Users/davea/Documents/workspace/myproject/app/helpers/webpage_helper.rb:55:in `rescue in get_content' 
/Users/davea/Documents/workspace/myproject/app/helpers/webpage_helper.rb:50:in `get_content' 
/Users/davea/Documents/workspace/myproject/app/helpers/webpage_helper.rb:14:in `get_url' 
/Users/davea/Documents/workspace/myproject/app/services/onlinerr_race_finder_service.rb:41:in `get_race_list' 
/Users/davea/Documents/workspace/myproject/app/services/abstract_race_finder_service.rb:26:in `process_data' 
/Users/davea/Documents/workspace/myproject/app/services/run_crawlers_service.rb:18:in `block in run_all_crawlers' 
/Users/davea/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.7.1/lib/active_record/relation/delegation.rb:46:in `each' 
/Users/davea/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.7.1/lib/active_record/relation/delegation.rb:46:in `each' 
/Users/davea/Documents/workspace/myproject/app/services/run_crawlers_service.rb:5:in `run_all_crawlers' 
(irb):2:in `irb_binding' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/irb/workspace.rb:87:in `eval' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/irb/workspace.rb:87:in `evaluate' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/irb/context.rb:380:in `evaluate' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/irb.rb:489:in `block (2 levels) in eval_input' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/irb.rb:623:in `signal_status' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/irb.rb:486:in `block in eval_input' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/irb/ruby-lex.rb:246:in `block (2 levels) in each_top_level_statement' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/irb/ruby-lex.rb:232:in `loop' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/irb/ruby-lex.rb:232:in `block in each_top_level_statement' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/irb/ruby-lex.rb:231:in `catch' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/irb/ruby-lex.rb:231:in `each_top_level_statement' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/irb.rb:485:in `eval_input' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/irb.rb:395:in `block in start' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/irb.rb:394:in `catch' 
/Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/irb.rb:394:in `start' 

मैं रूबी/टोर का उपयोग करके प्रोग्राम को आईपी एड्रेस चेंज कैसे लागू करूं?

संपादित करें: यहाँ क्या मैं अपने सहायक फ़ाइल में शामिल है और नीचे त्रुटि है कि परिणाम

require 'rubygems' 
$:.unshift "./tor/lib" 
require 'tor' 
… 
    cookie_file = '/Users/davea/Library/Application Support/TorBrowser-Data/Tor/control_auth_cookie' 
    file = File.open(cookie_file, 'rb') 
    cookie = file.read # read contents of auth cookie to string 
    file.close 

    Tor::Controller.connect(:port => 9150, :cookie => cookie) do |tor| 
     tor.signal('NEWNYM') # send NEWNYM signal (gets new IP) 
    end 

त्रुटि है कि रेल कंसोल में जो परिणाम है ...

Error during processing: undefined method `signal' for #<Tor::Controller:0x007fe044b1e550> 
/Users/davea/Documents/workspace/myproject/app/helpers/webpage_helper.rb:87:in `block in get_content' 
/Users/davea/.rvm/gems/ruby-2.3.0/gems/tor-0.1.2/lib/tor/control.rb:38:in `connect' 
/Users/davea/Documents/workspace/myproject/app/helpers/webpage_helper.rb:86:in `rescue in get_content' 

संपादित करें 2 :

इसे मेरी जेमफाइल फ़ाइल में जोड़ने के बाद

gem 'tor', :git => 'https://github.com/dryruby/tor.rb.git' 

मैं ऊपर कोड भाग गया, और अब त्रुटि मिली ...

Error during processing: end of file reached 
/Users/davea/.rvm/gems/ruby-2.3.0/bundler/gems/tor.rb-08e589d17196/lib/tor/control.rb:301:in `readline' 
/Users/davea/.rvm/gems/ruby-2.3.0/bundler/gems/tor.rb-08e589d17196/lib/tor/control.rb:301:in `read_reply' 
/Users/davea/.rvm/gems/ruby-2.3.0/bundler/gems/tor.rb-08e589d17196/lib/tor/control.rb:194:in `authenticate' 
/Users/davea/.rvm/gems/ruby-2.3.0/bundler/gems/tor.rb-08e589d17196/lib/tor/control.rb:282:in `send_command' 
/Users/davea/.rvm/gems/ruby-2.3.0/bundler/gems/tor.rb-08e589d17196/lib/tor/control.rb:269:in `signal' 
/Users/davea/Documents/workspace/myproject/app/helpers/webpage_helper.rb:90:in `block in get_content' 

उत्तर

3

टो में आपके आईपी बदलने के लिए, आप नियंत्रक से सीधे जुड़ने की जरूरत है (यह एक टेलनेट की तरह लाइन आधारित आदेश का उपयोग करता है/प्रतिक्रिया protocol

ऐसा लगता है कि आप Privoxy से कनेक्ट करने का प्रयास कर रहे हैं जो आवश्यक नहीं है। नियंत्रक केवल स्थानीय कनेक्शन को डिफ़ॉल्ट रूप से अनुमति देता है।

टोर ब्राउज़र की टोर कॉन्फ़िगरेशन प्रमाणीकरण लागू करता है कुकी विधि का उपयोग करता है, torrc में किसी भी विकल्प को बदलने के बिना आपको कनेक्ट करने के लिए ऑथ कुकी की सामग्री को पढ़ने की आवश्यकता है।

मैं निम्नलिखित कोड के साथ आईपी बदलने में सक्षम था:

require 'rubygems' 
$:.unshift "./tor/lib" 
require 'tor' 

# the cookie file contains a "password" for authentication, 32 random bytes 
cookie_file = '/home/me/tor-browser_en-US/Browser/TorBrowser/Data/Tor/control_auth_cookie' 
file = File.open(cookie_file, 'rb') 
cookie = file.read # read contents of auth cookie to string 
file.close 

Tor::Controller.connect(:port => 9151, :cookie => cookie) do |tor| 
    p tor.signal('NEWNYM') # send NEWNYM signal (gets new IP) 
end 

tor.signal एक स्ट्रिंग है, जो "250 ठीक है" पढ़ना चाहिए अगर NEWNYM आदेश सफल रहा था देता है। कुछ आंतरिक दर सीमित है जो इसे अक्सर चलाने से रोकती है (जैसे मुझे लगता है कि हर 10 सेकंड) जो आपके लिए कोई समस्या नहीं होनी चाहिए।

संपादित करें: इस जेम की 0.1.2 (वर्तमान रिलीज) में मास्टर शाखा से signal विधि शामिल नहीं है। सिग्नल कॉल करने के बजाय आपको नवीनतम कोड का उपयोग करना होगा या their code दोहराना होगा।

+0

जैसा कि मैंने उल्लेख किया है, मै मैक एल कैपिटन का उपयोग कर रहा हूं, तो मुझे "cookie_file =" के लिए क्या करना होगा? मेरे पास मशीन पर कहीं भी "control_auth_cookie" फ़ाइल नहीं है। – Dave

+0

यह टोर डेटा निर्देशिका के भीतर होना चाहिए कि टोर ब्राउज़र अन्य सभी नेटवर्क डेटा और राज्य फ़ाइलों के साथ बनाता है। – drew010

+0

कूल, मैंने इसे पाया।मैंने अपना कोड चलाने के आधार पर त्रुटि को सूचीबद्ध करने के लिए अपना उत्तर अपडेट किया (त्रुटि "प्रसंस्करण के दौरान त्रुटि: # " – Dave

संबंधित मुद्दे