Class: PassiveDNS::Provider::Mnemonic
- Inherits:
-
PassiveDNS::PassiveDB
- Object
- PassiveDNS::PassiveDB
- PassiveDNS::Provider::Mnemonic
- Defined in:
- lib/passivedns/client/provider/mnemonic.rb
Overview
Queries Mnemonic’s passive DNS database
Instance Attribute Summary collapse
-
#debug ⇒ Object
:debug enables verbose logging to standard output.
Class Method Summary collapse
-
.config_section_name ⇒ Object
Sets the configuration section name to “mnemonic”.
-
.name ⇒ Object
Sets the modules self-reported name to “Mnemonic”.
-
.option_letter ⇒ Object
Sets the command line database argument to “m”.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Mnemonic
constructor
Options * :debug Sets the debug flag for the module * “APIKEY” REQUIRED: The API key associated with Mnemonic * “URL” Alternate url for testing.
-
#lookup(label, limit = nil) ⇒ Object
Takes a label (either a domain or an IP address) and returns an array of PassiveDNS::PDNSResult instances with the answers to the query.
Constructor Details
#initialize(options = {}) ⇒ Mnemonic
Options
-
:debug Sets the debug flag for the module
-
“APIKEY” REQUIRED: The API key associated with Mnemonic
-
“URL” Alternate url for testing. Defaults to “passivedns.mnemonic.no/api1/?apikey=”
Example Instantiation
= {
:debug => true,
"APIKEY" => "01234567890abcdef01234567890abcdef012345",
"URL" => "https://passivedns.mnemonic.no/api1/?apikey="
}
PassiveDNS::Provider::Mnemonic.new()
42 43 44 45 46 |
# File 'lib/passivedns/client/provider/mnemonic.rb', line 42 def initialize(={}) @debug = [:debug] || false @apikey = ["APIKEY"] || raise("#{self.class.name} requires an APIKEY") @url = ["URL"] || "https://passivedns.mnemonic.no/api1/?apikey=" end |
Instance Attribute Details
#debug ⇒ Object
:debug enables verbose logging to standard output
26 27 28 |
# File 'lib/passivedns/client/provider/mnemonic.rb', line 26 def debug @debug end |
Class Method Details
.config_section_name ⇒ Object
Sets the configuration section name to “mnemonic”
17 18 19 |
# File 'lib/passivedns/client/provider/mnemonic.rb', line 17 def self.config_section_name "mnemonic" end |
.name ⇒ Object
Sets the modules self-reported name to “Mnemonic”
13 14 15 |
# File 'lib/passivedns/client/provider/mnemonic.rb', line 13 def self.name "Mnemonic" end |
.option_letter ⇒ Object
Sets the command line database argument to “m”
21 22 23 |
# File 'lib/passivedns/client/provider/mnemonic.rb', line 21 def self.option_letter "m" end |
Instance Method Details
#lookup(label, limit = nil) ⇒ Object
Takes a label (either a domain or an IP address) and returns an array of PassiveDNS::PDNSResult instances with the answers to the query
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 |
# File 'lib/passivedns/client/provider/mnemonic.rb', line 50 def lookup(label, limit=nil) $stderr.puts "DEBUG: #{self.class.name}.lookup(#{label})" if @debug Timeout::timeout(240) { url = "#{@url}#{@apikey}&query=#{label}&method=exact" $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.path+"?"+url.query) request.add_field("User-Agent", "Ruby/#{RUBY_VERSION} passivedns-client rubygem v#{PassiveDNS::Client::VERSION}") 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 |