Class: PassiveDNS::Circl
- Defined in:
- lib/passivedns/client/circl.rb
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
Class Method Summary collapse
-
.config_section_name ⇒ Object
override.
-
.name ⇒ Object
override.
-
.option_letter ⇒ Object
override.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Circl
constructor
A new instance of Circl.
- #lookup(label, limit = nil) ⇒ Object
- #parse_json(page, query, response_time = 0) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Circl
Returns a new instance of Circl.
24 25 26 27 28 29 30 |
# File 'lib/passivedns/client/circl.rb', line 24 def initialize(={}) @debug = [:debug] || true @username = ["USERNAME"] @password = ["PASSWORD"] @auth_token = ["AUTH_TOKEN"] @url = ["URL"] || "https://www.circl.lu/pdns/query" end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
23 24 25 |
# File 'lib/passivedns/client/circl.rb', line 23 def debug @debug end |
Class Method Details
.config_section_name ⇒ Object
override
15 16 17 |
# File 'lib/passivedns/client/circl.rb', line 15 def self.config_section_name "CIRCL" end |
.name ⇒ Object
override
11 12 13 |
# File 'lib/passivedns/client/circl.rb', line 11 def self.name "CIRCL" end |
.option_letter ⇒ Object
override
19 20 21 |
# File 'lib/passivedns/client/circl.rb', line 19 def self.option_letter "c" end |
Instance Method Details
#lookup(label, limit = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/passivedns/client/circl.rb', line 47 def lookup(label, limit=nil) $stderr.puts "DEBUG: #{self.class.name}.lookup(#{label})" if @debug Timeout::timeout(240) { url = @url+"/"+label $stderr.puts "DEBUG: #{self.class.name} url = #{url}" if @debug url = URI.parse url http = Net::HTTP.new(url.host, url.port) http.use_ssl = (url.scheme == 'https') http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.verify_depth = 5 request = Net::HTTP::Get.new(url.request_uri) request.add_field("User-Agent", "Ruby/#{RUBY_VERSION} passivedns-client rubygem v#{PassiveDNS::Client::VERSION}") if @username request.basic_auth(@username, @password) end if @auth_token request.add_field("Authorization", @auth_token) end t1 = Time.now response = http.request(request) t2 = Time.now recs = parse_json(response.body, label, t2-t1) if limit recs[0,limit] else recs end } rescue Timeout::Error => e $stderr.puts "#{self.class.name} lookup timed out: #{label}" end |
#parse_json(page, query, response_time = 0) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/passivedns/client/circl.rb', line 32 def parse_json(page,query,response_time=0) res = [] # need to remove the json_class tag or the parser will crap itself trying to find a class to align it to page.split(/\n/).each do |line| row = JSON.parse(line) res << PDNSResult.new(self.class.name,response_time, row['rrname'], row['rdata'], row['rrtype'], 0, row['time_first'], row['time_last'], row['count']) end res rescue Exception => e $stderr.puts "#{self.class.name} Exception: #{e}" raise e end |