Class: Dert::AXFR

Inherits:
Object
  • Object
show all
Defined in:
lib/dert/methods/axfr.rb

Class Method Summary collapse

Class Method Details

.query(domain) ⇒ Object



6
7
8
9
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
40
41
42
43
44
45
46
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/dert/methods/axfr.rb', line 6

def self.query(domain)
  default_address = Resolv.getaddress(domain)
  results = []
  begin
    ret = @res.query(domain, Dnsruby::Types.NS)
    name_servers = []
    ret.answer.each do |x|
      name_servers << x.domainname.to_s
    end
    zt = Dnsruby::ZoneTransfer.new
    zoneref = []
    name_servers.each do |x|
      begin
        zt.server = x
        zoneref = zt.transfer(domain)
        break
      rescue Dnsruby::ResolvError => e
        #
      end
    end

    zoneref.each do |x|
      case x.type.to_s
        when 'SOA'
          results << {
              address: default_address,
              type: x.type.to_s,
              hostname: x.name.to_s,
              ttl: x.ttl.to_s,
              klass: x.klass.to_s
          }
        when 'A'
          results << {
              address: x.address.to_s,
              type: x.type.to_s,
              hostname: x.name.to_s,
              ttl: x.ttl.to_s,
              klass: x.klass.to_s
          }
        when 'MX'
          results << {
              address: default_address,
              type: x.type.to_s,
              hostname: x.exchange.to_s,
              ttl: x.ttl.to_s,
              klass: x.klass.to_s,
              preference: x.preference.to_s
          }
        when 'NS'
          results << {
              address: default_address,
              type: x.type.to_s,
              hostname: x.domainname.to_s,
              ttl: x.ttl.to_s,
              klass: x.klass.to_s
          }
        when 'TXT'
          results << {
              address: default_address,
              type: x.type.to_s,
              hostname: x.name.to_s,
              ttl: x.ttl.to_s,
              klass: x.klass.to_s
          }
        when 'CNAME'
          results << {
              address: default_address,
              type: x.type.to_s,
              hostname: x.name.to_s,
              ttl: x.ttl.to_s,
              klass: x.klass.to_s
          }
        when 'SRV'
          results << {
              address: default_address,
              type: x.type.to_s,
              hostname: x.name.to_s,
              ttl: x.ttl.to_s,
              klass: x.klass.to_s
          }
        when 'LOC'
          results << {
              address: default_address,
              type: x.type.to_s,
              hostname: x.name.to_s,
              ttl: x.ttl.to_s,
              klass: x.klass.to_s
          }
        else
          #
      end
    end
  rescue => e
    #
  end

  results
end