Class: PassiveDNS::BFK

Inherits:
Object
  • Object
show all
Defined in:
lib/passivedns/client/bfk.rb

Constant Summary collapse

@@base =
"http://www.bfk.de/bfk_dnslogger.html?query="

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBFK

Returns a new instance of BFK.



6
7
8
# File 'lib/passivedns/client/bfk.rb', line 6

def initialize
  @debug = false
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



5
6
7
# File 'lib/passivedns/client/bfk.rb', line 5

def debug
  @debug
end

Instance Method Details

#lookup(label) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/passivedns/client/bfk.rb', line 41

def lookup(label) 
  $stderr.puts "DEBUG: BFKClient.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}",
      :http_basic_authentication => [@user,@pass]
    ) do |f|
      t2 = Time.now
      parse(f.read,t2-t1)
    end
  }
rescue Timeout::Error => e
  $stderr.puts "BFK lookup timed out: #{label}"      
end

#parse(page, response_time) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/passivedns/client/bfk.rb', line 10

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('BFK',response_time,r[0],r[2],r[1])
    end
  end
  res
rescue Exception => e
  $stderr.puts "BFKClient Exception: #{e}"
  raise e
end