Class: Ronin::Support::Network::DNS::Resolver
- Inherits:
- 
      Object
      
        - Object
- Ronin::Support::Network::DNS::Resolver
 
- Defined in:
- lib/ronin/support/network/dns/resolver.rb
Overview
Wraps around Resolv::DNS.
Constant Summary collapse
- RECORD_TYPES =
          This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future. Mapping of record type names to the Resolv::DNS::Resource::INclasses.
- { a: Resolv::DNS::Resource::IN::A, aaaa: Resolv::DNS::Resource::IN::AAAA, any: Resolv::DNS::Resource::IN::ANY, cname: Resolv::DNS::Resource::IN::CNAME, hinfo: Resolv::DNS::Resource::IN::HINFO, loc: Resolv::DNS::Resource::IN::LOC, minfo: Resolv::DNS::Resource::IN::MINFO, mx: Resolv::DNS::Resource::IN::MX, ns: Resolv::DNS::Resource::IN::NS, ptr: Resolv::DNS::Resource::IN::PTR, soa: Resolv::DNS::Resource::IN::SOA, srv: Resolv::DNS::Resource::IN::SRV, txt: Resolv::DNS::Resource::IN::TXT, wks: Resolv::DNS::Resource::IN::WKS } 
Instance Attribute Summary collapse
- 
  
    
      #nameservers  ⇒ Array<String> 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The nameserver(s) to query. 
Class Method Summary collapse
- 
  
    
      .default_nameservers  ⇒ Array<String> 
    
    
  
  
  
  
  
  
  
  
  
    The system's nameserver(s) to use by default. 
Instance Method Summary collapse
- 
  
    
      #get_a_address(name)  ⇒ String? 
    
    
      (also: #get_ipv4_address)
    
  
  
  
  
  
  
  
  
  
    Queries the first IPv4 address belonging to the host name. 
- 
  
    
      #get_a_addresses(name)  ⇒ Array<String> 
    
    
      (also: #get_ipv4_addresses)
    
  
  
  
  
  
  
  
  
  
    Queries all IPv4 addresses belonging to the host name. 
- 
  
    
      #get_a_record(name)  ⇒ Resolv::DNS::Resource::IN::A? 
    
    
  
  
  
  
  
  
  
  
  
    Queries the first Arecord belonging to the host name.
- 
  
    
      #get_a_records(name)  ⇒ Array<Resolv::DNS::Resource::IN::A> 
    
    
  
  
  
  
  
  
  
  
  
    Queries all Arecords belonging to the host name.
- 
  
    
      #get_aaaa_address(name)  ⇒ String? 
    
    
      (also: #get_ipv6_address)
    
  
  
  
  
  
  
  
  
  
    Queries the first IPv6 address belonging to the host name. 
- 
  
    
      #get_aaaa_addresses(name)  ⇒ Array<String> 
    
    
      (also: #get_ipv6_addresses)
    
  
  
  
  
  
  
  
  
  
    Queries all IPv6 addresses belonging to the host name. 
- 
  
    
      #get_aaaa_record(name)  ⇒ Resolv::DNS::Resource::IN::AAAA? 
    
    
  
  
  
  
  
  
  
  
  
    Queries the first AAAADNS records belonging to the host name.
- 
  
    
      #get_aaaa_records(name)  ⇒ Array<Resolv::DNS::Resource::IN::AAAA> 
    
    
  
  
  
  
  
  
  
  
  
    Queries all AAAADNS records belonging to the host name.
- 
  
    
      #get_address(host)  ⇒ String? 
    
    
  
  
  
  
  
  
  
  
  
    Queries the first IP address for the given host name. 
- 
  
    
      #get_addresses(host)  ⇒ Array<String> 
    
    
  
  
  
  
  
  
  
  
  
    Queries all IP addresses for the given host name. 
- 
  
    
      #get_any_records(name)  ⇒ Array<Resolv::DNS::Resource> 
    
    
  
  
  
  
  
  
  
  
  
    Queries all records of the host name using the ANYDNS query.
- 
  
    
      #get_cname(name)  ⇒ String? 
    
    
  
  
  
  
  
  
  
  
  
    Queries the canonical name for the host name. 
- 
  
    
      #get_cname_record(name)  ⇒ Resolv::DNS::Resource::IN::CNAME? 
    
    
  
  
  
  
  
  
  
  
  
    Queries the CNAMErecord for the host name.
- 
  
    
      #get_hinfo_record(name)  ⇒ Resolv::DNS::Resource::IN::HINFO? 
    
    
  
  
  
  
  
  
  
  
  
    Queries the HINFOrecord for the host name.
- 
  
    
      #get_ip_address(name)  ⇒ String? 
    
    
  
  
  
  
  
  
  
  
  
    Queries the first IPv4 or IPv6 address belonging to the host name. 
- 
  
    
      #get_ip_addresses(name)  ⇒ Array<String> 
    
    
  
  
  
  
  
  
  
  
  
    Queries all IPv4 and IPv6 addresses belonging to the host name. 
- 
  
    
      #get_loc_record(name)  ⇒ Resolv::DNS::Resource::LOC? 
    
    
  
  
  
  
  
  
  
  
  
    Queries the LOC(Location) DNS record of the host name.
- 
  
    
      #get_mailservers(name)  ⇒ Array<String> 
    
    
  
  
  
  
  
  
  
  
  
    Queries the mailservers for the host name. 
- 
  
    
      #get_minfo_record(name)  ⇒ Resolv::DNS::Resource::MINFO? 
    
    
  
  
  
  
  
  
  
  
  
    Queries the MINFO(Machine-Info) DNS record of the host name.
- 
  
    
      #get_mx_records(name)  ⇒ Array<Resolv::DNS::Resource::MX> 
    
    
  
  
  
  
  
  
  
  
  
    Queries all MXDNS records belonging to the host name.
- 
  
    
      #get_name(ip)  ⇒ String? 
    
    
  
  
  
  
  
  
  
  
  
    Reverse-queries the first host name for the given IP address. 
- 
  
    
      #get_names(ip)  ⇒ Array<String> 
    
    
  
  
  
  
  
  
  
  
  
    Reverse-queries all host names for the given IP address. 
- 
  
    
      #get_nameservers(name)  ⇒ Array<String> 
    
    
  
  
  
  
  
  
  
  
  
    Queries the nameservers for the host name. 
- 
  
    
      #get_ns_records(name)  ⇒ Array<Resolv::DNS::Resource::NS> 
    
    
  
  
  
  
  
  
  
  
  
    Queries all NSDNS records belonging to the host name.
- 
  
    
      #get_ptr_name(ip)  ⇒ String? 
    
    
  
  
  
  
  
  
  
  
  
    Queries the PTRhost name for the IP address.
- 
  
    
      #get_ptr_names(ip)  ⇒ Array<String> 
    
    
  
  
  
  
  
  
  
  
  
    Queries all PTRnames for the IP address.
- 
  
    
      #get_ptr_record(ip)  ⇒ Resolv::DNS::Resource::PTR? 
    
    
  
  
  
  
  
  
  
  
  
    Queries the first PTRDNS record for the IP address.
- 
  
    
      #get_ptr_records(ip)  ⇒ Array<Resolv::DNS::Resource::PTR> 
    
    
  
  
  
  
  
  
  
  
  
    Queries all PTRDNS records for the IP address.
- 
  
    
      #get_record(name, record_type)  ⇒ Resolv::DNS::Resource? 
    
    
  
  
  
  
  
  
  
  
  
    Queries a single matching DNS record for the host name. 
- 
  
    
      #get_records(name, record_type)  ⇒ Array<Resolv::DNS::Resource> 
    
    
  
  
  
  
  
  
  
  
  
    Queries all matching DNS records for the host name. 
- 
  
    
      #get_soa_record(name)  ⇒ Resolv::DNS::Resource::SOA? 
    
    
  
  
  
  
  
  
  
  
  
    Queries the first SOADNS record belonging to the host name.
- 
  
    
      #get_srv_records(name)  ⇒ Array<Resolv::DNS::Resource::IN::SRV> 
    
    
  
  
  
  
  
  
  
  
  
    Queries all SRVDNS records belonging to the host name.
- 
  
    
      #get_txt_record(name)  ⇒ Resolv::DNS::Resource::TXT? 
    
    
  
  
  
  
  
  
  
  
  
    Queiries the first TXTDNS record belonging to the host name.
- 
  
    
      #get_txt_records(name)  ⇒ Array<Resolv::DNS::Resource::TXT> 
    
    
  
  
  
  
  
  
  
  
  
    Queries all TXTDNS records belonging to the host name.
- 
  
    
      #get_txt_string(name)  ⇒ String? 
    
    
  
  
  
  
  
  
  
  
  
    Queries the first TXTstring belonging to the host name.
- 
  
    
      #get_txt_strings(name)  ⇒ Array<String> 
    
    
  
  
  
  
  
  
  
  
  
    Queries all of the TXTstring values of the host name.
- 
  
    
      #get_wks_records(name)  ⇒ Array<Resolv::DNS::Resource::IN::WKS> 
    
    
  
  
  
  
  
  
  
  
  
    Queries all WKS(Well-Known-Service) DNS records belonging to the host name.
- 
  
    
      #initialize(nameservers: self.class.default_nameservers, nameserver: nil)  ⇒ Resolver 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Initializes the resolver. 
Constructor Details
#initialize(nameservers: self.class.default_nameservers, nameserver: nil) ⇒ Resolver
Initializes the resolver.
| 58 59 60 61 62 63 64 65 | # File 'lib/ronin/support/network/dns/resolver.rb', line 58 def initialize(nameservers: self.class.default_nameservers, nameserver: nil) @nameservers = if nameserver then [nameserver] else nameservers end @resolver = Resolv::DNS.new(nameserver: @nameservers) end | 
Instance Attribute Details
Class Method Details
Instance Method Details
#get_a_address(name) ⇒ String? Also known as: get_ipv4_address
Queries the first IPv4 address belonging to the host name.
| 313 314 315 316 317 | # File 'lib/ronin/support/network/dns/resolver.rb', line 313 def get_a_address(name) if (a = get_a_record(name)) a.address.to_s end end | 
#get_a_addresses(name) ⇒ Array<String> Also known as: get_ipv4_addresses
Queries all IPv4 addresses belonging to the host name.
| 345 346 347 348 349 | # File 'lib/ronin/support/network/dns/resolver.rb', line 345 def get_a_addresses(name) records = get_a_records(name) records.map! { |a| a.address.to_s } records end | 
#get_a_record(name) ⇒ Resolv::DNS::Resource::IN::A?
Queries the first A record belonging to the host name.
| 300 301 302 | # File 'lib/ronin/support/network/dns/resolver.rb', line 300 def get_a_record(name) get_record(name,:a) end | 
#get_a_records(name) ⇒ Array<Resolv::DNS::Resource::IN::A>
Queries all A records belonging to the host name.
| 332 333 334 | # File 'lib/ronin/support/network/dns/resolver.rb', line 332 def get_a_records(name) get_records(name,:a) end | 
#get_aaaa_address(name) ⇒ String? Also known as: get_ipv6_address
Queries the first IPv6 address belonging to the host name.
| 379 380 381 382 383 | # File 'lib/ronin/support/network/dns/resolver.rb', line 379 def get_aaaa_address(name) if (aaaa = get_aaaa_record(name)) aaaa.address.to_s end end | 
#get_aaaa_addresses(name) ⇒ Array<String> Also known as: get_ipv6_addresses
Queries all IPv6 addresses belonging to the host name.
| 411 412 413 414 415 | # File 'lib/ronin/support/network/dns/resolver.rb', line 411 def get_aaaa_addresses(name) records = get_aaaa_records(name) records.map! { |aaaa| aaaa.address.to_s } records end | 
#get_aaaa_record(name) ⇒ Resolv::DNS::Resource::IN::AAAA?
Queries the first AAAA DNS records belonging to the host name.
| 365 366 367 | # File 'lib/ronin/support/network/dns/resolver.rb', line 365 def get_aaaa_record(name) get_record(name,:aaaa) end | 
#get_aaaa_records(name) ⇒ Array<Resolv::DNS::Resource::IN::AAAA>
Queries all AAAA DNS records belonging to the host name.
| 398 399 400 | # File 'lib/ronin/support/network/dns/resolver.rb', line 398 def get_aaaa_records(name) get_records(name,:aaaa) end | 
#get_address(host) ⇒ String?
Queries the first IP address for the given host name.
| 87 88 89 90 91 92 93 94 95 | # File 'lib/ronin/support/network/dns/resolver.rb', line 87 def get_address(host) host = IDN.to_ascii(host) begin @resolver.getaddress(host).to_s rescue Resolv::ResolvError # ignore any Resolv failures end end | 
#get_addresses(host) ⇒ Array<String>
Queries all IP addresses for the given host name.
| 106 107 108 109 110 111 112 | # File 'lib/ronin/support/network/dns/resolver.rb', line 106 def get_addresses(host) host = IDN.to_ascii(host) addresses = @resolver.getaddresses(host) addresses.map!(&:to_s) return addresses end | 
#get_any_records(name) ⇒ Array<Resolv::DNS::Resource>
Queries all records of the host name using the ANY DNS query.
| 236 237 238 | # File 'lib/ronin/support/network/dns/resolver.rb', line 236 def get_any_records(name) get_records(name,:any) end | 
#get_cname(name) ⇒ String?
Queries the canonical name for the host name.
| 266 267 268 269 270 | # File 'lib/ronin/support/network/dns/resolver.rb', line 266 def get_cname(name) if (cname = get_cname_record(name)) cname.name.to_s end end | 
#get_cname_record(name) ⇒ Resolv::DNS::Resource::IN::CNAME?
Queries the CNAME record for the host name.
| 252 253 254 | # File 'lib/ronin/support/network/dns/resolver.rb', line 252 def get_cname_record(name) get_record(name,:cname) end | 
#get_hinfo_record(name) ⇒ Resolv::DNS::Resource::IN::HINFO?
Queries the HINFO record for the host name.
| 284 285 286 | # File 'lib/ronin/support/network/dns/resolver.rb', line 284 def get_hinfo_record(name) get_record(name,:hinfo) end | 
#get_ip_address(name) ⇒ String?
Queries the first IPv4 or IPv6 address belonging to the host name.
| 429 430 431 | # File 'lib/ronin/support/network/dns/resolver.rb', line 429 def get_ip_address(name) get_ipv4_address(name) || get_ipv6_address(name) end | 
#get_ip_addresses(name) ⇒ Array<String>
Queries all IPv4 and IPv6 addresses belonging to the host name.
| 442 443 444 | # File 'lib/ronin/support/network/dns/resolver.rb', line 442 def get_ip_addresses(name) get_ipv4_addresses(name).concat(get_ipv6_addresses(name)) end | 
#get_loc_record(name) ⇒ Resolv::DNS::Resource::LOC?
Queries the LOC (Location) DNS record of the host name.
| 489 490 491 | # File 'lib/ronin/support/network/dns/resolver.rb', line 489 def get_loc_record(name) get_record(name,:loc) end | 
#get_mailservers(name) ⇒ Array<String>
Queries the mailservers for the host name.
| 533 534 535 536 537 | # File 'lib/ronin/support/network/dns/resolver.rb', line 533 def get_mailservers(name) records = get_mx_records(name) records.map! { |mx| mx.exchange.to_s } records end | 
#get_minfo_record(name) ⇒ Resolv::DNS::Resource::MINFO?
Queries the MINFO (Machine-Info) DNS record of the host name.
| 505 506 507 | # File 'lib/ronin/support/network/dns/resolver.rb', line 505 def get_minfo_record(name) get_record(name,:minfo) end | 
#get_mx_records(name) ⇒ Array<Resolv::DNS::Resource::MX>
Queries all MX DNS records belonging to the host name.
| 520 521 522 | # File 'lib/ronin/support/network/dns/resolver.rb', line 520 def get_mx_records(name) get_records(name,:mx) end | 
#get_name(ip) ⇒ String?
Reverse-queries the first host name for the given IP address.
| 124 125 126 127 128 | # File 'lib/ronin/support/network/dns/resolver.rb', line 124 def get_name(ip) @resolver.getname(ip).to_s rescue Resolv::ResolvError # ignore any Resolv failures end | 
#get_names(ip) ⇒ Array<String>
Reverse-queries all host names for the given IP address.
| 139 140 141 142 143 | # File 'lib/ronin/support/network/dns/resolver.rb', line 139 def get_names(ip) names = @resolver.getnames(ip) names.map!(&:to_s) names end | 
#get_nameservers(name) ⇒ Array<String>
Queries the nameservers for the host name.
| 563 564 565 566 567 | # File 'lib/ronin/support/network/dns/resolver.rb', line 563 def get_nameservers(name) records = get_ns_records(name) records.map! { |ns| ns.name.to_s } records end | 
#get_ns_records(name) ⇒ Array<Resolv::DNS::Resource::NS>
Queries all NS DNS records belonging to the host name.
| 550 551 552 | # File 'lib/ronin/support/network/dns/resolver.rb', line 550 def get_ns_records(name) get_records(name,:ns) end | 
#get_ptr_name(ip) ⇒ String?
Queries the PTR host name for the IP address.
| 594 595 596 597 598 | # File 'lib/ronin/support/network/dns/resolver.rb', line 594 def get_ptr_name(ip) if (ptr = get_ptr_record(ip)) ptr.name.to_s end end | 
#get_ptr_names(ip) ⇒ Array<String>
Queries all PTR names for the IP address.
| 624 625 626 627 628 | # File 'lib/ronin/support/network/dns/resolver.rb', line 624 def get_ptr_names(ip) records = get_ptr_records(ip) records.map! { |ptr| ptr.name.to_s } records end | 
#get_ptr_record(ip) ⇒ Resolv::DNS::Resource::PTR?
Queries the first PTR DNS record for the IP address.
| 581 582 583 | # File 'lib/ronin/support/network/dns/resolver.rb', line 581 def get_ptr_record(ip) get_record(ip,:ptr) end | 
#get_ptr_records(ip) ⇒ Array<Resolv::DNS::Resource::PTR>
Queries all PTR DNS records for the IP address.
| 611 612 613 | # File 'lib/ronin/support/network/dns/resolver.rb', line 611 def get_ptr_records(ip) get_records(ip,:ptr) end | 
#get_record(name, record_type) ⇒ Resolv::DNS::Resource?
Queries a single matching DNS record for the host name.
| 184 185 186 187 188 189 190 191 192 193 194 195 196 | # File 'lib/ronin/support/network/dns/resolver.rb', line 184 def get_record(name,record_type) name = IDN.to_ascii(name) record_class = RECORD_TYPES.fetch(record_type) do raise(ArgumentError,"record type (#{record_type.inspect}) must be #{RECORD_TYPES.keys.map(&:inspect).join(', ')}") end begin @resolver.getresource(name,record_class) rescue Resolv::ResolvError # ignore any Resolv failures end end | 
#get_records(name, record_type) ⇒ Array<Resolv::DNS::Resource>
Queries all matching DNS records for the host name.
| 215 216 217 218 219 220 221 222 223 | # File 'lib/ronin/support/network/dns/resolver.rb', line 215 def get_records(name,record_type) name = IDN.to_ascii(name) record_class = RECORD_TYPES.fetch(record_type) do raise(ArgumentError,"record type (#{record_type.inspect}) must be #{RECORD_TYPES.keys.map(&:inspect).join(', ')}") end @resolver.getresources(name,record_class) end | 
#get_soa_record(name) ⇒ Resolv::DNS::Resource::SOA?
Queries the first SOA DNS record belonging to the host name.
| 642 643 644 | # File 'lib/ronin/support/network/dns/resolver.rb', line 642 def get_soa_record(name) get_record(name,:soa) end | 
#get_srv_records(name) ⇒ Array<Resolv::DNS::Resource::IN::SRV>
Queries all SRV DNS records belonging to the host name.
| 457 458 459 | # File 'lib/ronin/support/network/dns/resolver.rb', line 457 def get_srv_records(name) get_records(name,:srv) end | 
#get_txt_record(name) ⇒ Resolv::DNS::Resource::TXT?
Queiries the first TXT DNS record belonging to the host name.
| 658 659 660 | # File 'lib/ronin/support/network/dns/resolver.rb', line 658 def get_txt_record(name) get_record(name,:txt) end | 
#get_txt_records(name) ⇒ Array<Resolv::DNS::Resource::TXT>
Queries all TXT DNS records belonging to the host name.
| 689 690 691 | # File 'lib/ronin/support/network/dns/resolver.rb', line 689 def get_txt_records(name) get_records(name,:txt) end | 
#get_txt_string(name) ⇒ String?
Queries the first TXT string belonging to the host name.
| 672 673 674 675 676 | # File 'lib/ronin/support/network/dns/resolver.rb', line 672 def get_txt_string(name) if (txt = get_txt_record(name)) txt.strings.join end end | 
#get_txt_strings(name) ⇒ Array<String>
Queries all of the TXT string values of the host name.
| 702 703 704 705 706 | # File 'lib/ronin/support/network/dns/resolver.rb', line 702 def get_txt_strings(name) get_txt_records(name).map do |txt| txt.strings.join end end | 
#get_wks_records(name) ⇒ Array<Resolv::DNS::Resource::IN::WKS>
Queries all WKS (Well-Known-Service) DNS records belonging to the
host name.
| 473 474 475 | # File 'lib/ronin/support/network/dns/resolver.rb', line 473 def get_wks_records(name) get_records(name,:wks) end |