class PassiveDNS::Provider::Circl
Queries CIRCL.LU’s passive DNS database Circl is aliased by CIRCL
Attributes
:debug enables verbose logging to standard output
Public Class Methods
Source
# File lib/passivedns/client/provider/circl.rb, line 24 def self.config_section_name 'circl' end
Sets the configuration section name to “circl”
Source
# File lib/passivedns/client/provider/circl.rb, line 19 def self.name 'CIRCL' end
Sets the modules self-reported name to “CIRCL”
Source
# File lib/passivedns/client/provider/circl.rb, line 56 def initialize(config = {}) super() @debug = config[:debug] || false @timeout = config[:timeout] || 20 @username = config['USERNAME'] @password = config['PASSWORD'] @auth_token = config['AUTH_TOKEN'] @url = config['URL'] || 'https://www.circl.lu/pdns/query' end
You should either have a username+password or an authorization token to use this service
Example Instantiation¶ ↑
options = { :debug => true, "USERNAME" => "circl_user", "PASSWORD" => "circl_pass", "URL" => "https://www.circl.lu/pdns/query" } PassiveDNS::Provider::CIRCL.new(options)
Calls superclass method
Source
# File lib/passivedns/client/provider/circl.rb, line 29 def self.option_letter 'c' end
Sets the command line database argument to “c”
Public Instance Methods
Source
# File lib/passivedns/client/provider/circl.rb, line 68 def lookup(label, limit = nil) warn "DEBUG: #{self.class.name}.lookup(#{label})" if @debug recs = [] Timeout.timeout @timeout do url = "#{@url}/#{label}" warn "DEBUG: #{self.class.name} url = #{url}" if @debug begin url = URI.parse url rescue URI::InvalidURIError warn "ERROR: Invalid address: #{url}" return recs end http = Net::HTTP.new url.host, url.port http.use_ssl = (url.scheme == 'https') 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}" request.basic_auth @username, @password if @username request.add_field 'Authorization', @auth_token if @auth_token t1 = Time.now 0.upto 9 do response = http.request request body = response.body if body == 'Rate Limit Exceeded' warn "DEBUG: Rate Limit Exceeded. Retrying #{label}" if @debug else check_response response t2 = Time.now recs = parse_json response.body, label, t2 - t1 break end end if limit recs[0, limit] else recs end end rescue Timeout::Error warn "#{self.class.name} lookup timed out: #{label}" recs end
Takes a label (either a domain or an IP address) and returns an array of PassiveDNS::PDNSResult instances with the answers to the query
Private Instance Methods
Source
# File lib/passivedns/client/provider/circl.rb, line 114 def parse_json(page, _query, response_time = 0) res = [] page.split("\n").each do |line| row = JSON.parse line firstseen = Time.at row['time_first'].to_i lastseen = Time.at row['time_last'].to_i res << PDNSResult.new(self.class.name, response_time, row['rrname'], row['rdata'], row['rrtype'], 0, firstseen, lastseen, row['count'], 'yellow') end res rescue StandardError => e warn "#{self.class.name} Exception: #{e}" raise e end
parses the response of circl’s JSON reply to generate an array of PDNSResult