Class: PassiveDNS::BFK
- Defined in:
- lib/passivedns/client/bfk.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 = {}) ⇒ BFK
constructor
A new instance of BFK.
-
#lookup(label, limit = nil) ⇒ Object
override.
- #parse(page, response_time) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ BFK
Returns a new instance of BFK.
20 21 22 23 |
# File 'lib/passivedns/client/bfk.rb', line 20 def initialize(={}) @debug = [:debug] || false @base = ["URL"] || "http://www.bfk.de/bfk_dnslogger.html?query=" end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
19 20 21 |
# File 'lib/passivedns/client/bfk.rb', line 19 def debug @debug end |
Class Method Details
.config_section_name ⇒ Object
override
11 12 13 |
# File 'lib/passivedns/client/bfk.rb', line 11 def self.config_section_name "bfk" end |
.name ⇒ Object
override
7 8 9 |
# File 'lib/passivedns/client/bfk.rb', line 7 def self.name "BFK.de" end |
.option_letter ⇒ Object
override
15 16 17 |
# File 'lib/passivedns/client/bfk.rb', line 15 def self.option_letter "b" end |
Instance Method Details
#lookup(label, limit = nil) ⇒ Object
override
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/passivedns/client/bfk.rb', line 57 def lookup(label, limit=nil) $stderr.puts "DEBUG: #{self.class.name}.lookup(#{label})" if @debug Timeout::timeout(240) { t1 = Time.now open( @base+label, "User-Agent" => "Ruby/#{RUBY_VERSION} passivedns-client rubygem v#{PassiveDNS::Client::VERSION}" ) do |f| t2 = Time.now recs = parse(f.read,t2-t1) if limit recs[0,limit] else recs end end } rescue Timeout::Error => e $stderr.puts "#{self.class.name} lookup timed out: #{label}" end |
#parse(page, response_time) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/passivedns/client/bfk.rb', line 25 def parse(page,response_time) line = page.unpack('C*').pack('U*').split(/<table/).grep(/ id=\"logger\"/) return [] unless line.length > 0 line = line[0].gsub(/[\t\n]/,'').gsub(/<\/table.*/,'') rows = line.split(/<tr.*?>/) res = [] rows.collect do |row| r = row.split(/<td>/).map{|x| x.gsub(/<.*?>/,'').gsub(/\&.*?;/,'')}[1,1000] if r and r[0] =~ /\w/ # BFK includes the MX weight in the answer response. First, find the MX records, then dump the weight to present a consistent record name to the collecting array. Otherwise the other repositories will present the same answer and your results will become cluttered with duplicates. if r[1] == "MX" then # MX lines look like "5 mx.domain.tld", so split on the space and assign r[2] (:answer) to the latter part. #s = r[2].split(/\w/).map{|x| x}[1,1000] # r[2] = s[1] r[2] =~ /[0-9]+?\s(.+)/ s=$1 puts "DEBUG: == BFK: MX Parsing Strip: Answer: " + r[2] + " : mod: " + s if @debug r[2] = s ######### FIX BLANKS FOR MX end res << PDNSResult.new(self.class.name,response_time,r[0],r[2],r[1]) end end res rescue Exception => e $stderr.puts "#{self.class.name} Exception: #{e}" raise e end |