Class: Ronin::Support::Network::Host

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/support/network/host.rb

Overview

Represents a host or host name.

Examples

host = Host.new('www.example.com')

Resolve parent domain:

host.domain
# => #<Ronin::Support::Network::Domain: example.co.uk>

Resolve IP addresses:

host.get_address
# => "172.67.128.149"
host.get_addresses
# => ["104.21.2.18", "172.67.128.149"]
host.get_ip
# => #<Ronin::Support::Network::IP: 172.67.128.149>
host.get_ips
# => [#<Ronin::Support::Network::IP: 104.21.2.18>, #<Ronin::Support::Network::IP: 172.67.128.149>]
host.ip
# => #<Ronin::Support::Network::IP: 172.67.128.149>
host.ips
# => [#<Ronin::Support::Network::IP: 104.21.2.18>, #<Ronin::Support::Network::IP: 172.67.128.149>]

Other DNS queries:

host = Host.new('www.github.com')
host.get_record(:txt)
# => #<Resolv::DNS::Resource::IN::TXT:0x00007f7e500777d8 @strings=["MS=ms58704441"], @ttl=3575>
host.get_records(:txt)
# => [#<Resolv::DNS::Resource::IN::TXT:0x00007f7e500777d8 @strings=["MS=ms58704441"], @ttl=3575>, ...]
host.get_cname_record
# => #<Resolv::DNS::Resource::IN::CNAME:0x00007f7e50063da0 @name=#<Resolv::DNS::Name: github.com.>, @ttl=3500>
host.get_cname
# => "github.com"
host.cname
# => "github.com"
host.get_mx_records
# => [#<Resolv::DNS::Resource::IN::MX:0x00007f7e50035658 @exchange=#<Resolv::DNS::Name: aspmx.l.google.com.>, @preference=1, @ttl=3600>, ...]
host.get_mailservers
# => ["alt1.aspmx.l.google.com",
#     "alt4.aspmx.l.google.com",
#     "alt3.aspmx.l.google.com",
#     "alt2.aspmx.l.google.com",
#     "aspmx.l.google.com"]
host.mailservers
# => ["alt1.aspmx.l.google.com",
#     "alt4.aspmx.l.google.com",
#     "alt3.aspmx.l.google.com",
#     "alt2.aspmx.l.google.com",
#     "aspmx.l.google.com"]
host.get_ns_records
# => [#<Resolv::DNS::Resource::IN::NS:0x00007f7e4f972258 @name=#<Resolv::DNS::Name: dns1.p08.nsone.net.>, @ttl=900>, ...]
host.get_nameservers
# => ["dns3.p08.nsone.net",
#     "ns-1707.awsdns-21.co.uk",
#     "dns2.p08.nsone.net",
#     "ns-1283.awsdns-32.org",
#     "dns4.p08.nsone.net",
#     "ns-421.awsdns-52.com",
#     "dns1.p08.nsone.net",
#     "ns-520.awsdns-01.net"]
host.nameservers
# => ["dns3.p08.nsone.net",
#     "ns-1707.awsdns-21.co.uk",
#     "dns2.p08.nsone.net",
#     "ns-1283.awsdns-32.org",
#     "dns4.p08.nsone.net",
#     "ns-421.awsdns-52.com",
#     "dns1.p08.nsone.net",
#     "ns-520.awsdns-01.net"]
host.get_soa_record
# => #<Resolv::DNS::Resource::IN::SOA:0x00007f7e4f63d0b0 @mname=#<Resolv::DNS::Name: ns-1707.awsdns-21.co.uk.>, @rname=#<Resolv::DNS::Name: awsdns-hostmaster.amazon.com.>, @serial=1, @refresh=7200, @retry=900, @expire=1209600, @minimum=86400, @ttl=880>
host.soa_record
# => #<Resolv::DNS::Resource::IN::SOA:0x00007f7e4f63d0b0 @mname=#<Resolv::DNS::Name: ns-1707.awsdns-21.co.uk.>, @rname=#<Resolv::DNS::Name: awsdns-hostmaster.amazon.com.>, @serial=1, @refresh=7200, @retry=900, @expire=1209600, @minimum=86400, @ttl=880>
host.get_txt_record
# => #<Resolv::DNS::Resource::IN::TXT:0x00007f7e4f8cbbb0 @strings=[\"adobe-idp-site-verification=b92c9e999aef825edc36e0a3d847d2dbad5b2fc0e05c79ddd7a16139b48ecf4b\"], @ttl=2887>
host.get_txt_string
# => "stripe-verification=f88ef17321660a01bab1660454192e014defa29ba7b8de9633c69d6b4912217f"
host.get_txt_records
# => [#<Resolv::DNS::Resource::IN::TXT:0x00007f7e4f67c648 @strings=[\"apple-domain-verification=RyQhdzTl6Z6x8ZP4\"], @ttl=2852>, ...]
host.get_txt_strings
# => ["apple-domain-verification=RyQhdzTl6Z6x8ZP4",
#     "MS=ms58704441",
#     "atlassian-domain-verification=jjgw98AKv2aeoYFxiL/VFaoyPkn3undEssTRuMg6C/3Fp/iqhkV4HVV7WjYlVeF8",
#     "MS=6BF03E6AF5CB689E315FB6199603BABF2C88D805",
#     "v=spf1 ip4:192.30.252.0/22 include:_netblocks.google.com include:_netblocks2.google.com include:_netblocks3.google.com include:spf.protection.outlook.com include:mail.zendesk.com include:_spf.salesforce.com include:servers.mcsv.net ip4:166.78.69.169 ip4:1",
#     "66.78.69.170 ip4:166.78.71.131 ip4:167.89.101.2 ip4:167.89.101.192/28 ip4:192.254.112.60 ip4:192.254.112.98/31 ip4:192.254.113.10 ip4:192.254.113.101 ip4:192.254.114.176 ip4:62.253.227.114 ~all",
#     "docusign=087098e3-3d46-47b7-9b4e-8a23028154cd",
#     "google-site-verification=UTM-3akMgubp6tQtgEuAkYNYLyYAvpTnnSrDMWoDR3o",
#     "stripe-verification=f88ef17321660a01bab1660454192e014defa29ba7b8de9633c69d6b4912217f",
#     "adobe-idp-site-verification=b92c9e999aef825edc36e0a3d847d2dbad5b2fc0e05c79ddd7a16139b48ecf4b",
#     "MS=ms44452932"]
host.txt_strings
# => ["apple-domain-verification=RyQhdzTl6Z6x8ZP4",
#     "MS=ms58704441",
#     "atlassian-domain-verification=jjgw98AKv2aeoYFxiL/VFaoyPkn3undEssTRuMg6C/3Fp/iqhkV4HVV7WjYlVeF8",
#     "MS=6BF03E6AF5CB689E315FB6199603BABF2C88D805",
#     "v=spf1 ip4:192.30.252.0/22 include:_netblocks.google.com include:_netblocks2.google.com include:_netblocks3.google.com include:spf.protection.outlook.com include:mail.zendesk.com include:_spf.salesforce.com include:servers.mcsv.net ip4:166.78.69.169 ip4:1",
#     "66.78.69.170 ip4:166.78.71.131 ip4:167.89.101.2 ip4:167.89.101.192/28 ip4:192.254.112.60 ip4:192.254.112.98/31 ip4:192.254.113.10 ip4:192.254.113.101 ip4:192.254.114.176 ip4:62.253.227.114 ~all",
#     "docusign=087098e3-3d46-47b7-9b4e-8a23028154cd",
#     "google-site-verification=UTM-3akMgubp6tQtgEuAkYNYLyYAvpTnnSrDMWoDR3o",
#     "stripe-verification=f88ef17321660a01bab1660454192e014defa29ba7b8de9633c69d6b4912217f",
#     "adobe-idp-site-verification=b92c9e999aef825edc36e0a3d847d2dbad5b2fc0e05c79ddd7a16139b48ecf4b",
#     "MS=ms44452932"]

Since:

  • 1.0.0

Direct Known Subclasses

Domain

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Host

Initializes the host.

Examples:

host = Host.new('www.example.com')

Parameters:

  • name (String)

    The host's hostname.

Since:

  • 1.0.0



157
158
159
# File 'lib/ronin/support/network/host.rb', line 157

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameString (readonly)

The host name.

Returns:

Since:

  • 1.0.0



146
147
148
# File 'lib/ronin/support/network/host.rb', line 146

def name
  @name
end

Instance Method Details

#addressesArray<String>

Note:

This method returns memoized data.

The addreses of the hostname.

Examples:

host = Host.new('www.example.com')
host.addresses
# => ["104.21.2.18", "172.67.128.149"]

Returns:

  • (Array<String>)

    The addresses associated with the hostname.

Since:

  • 1.0.0



440
441
442
# File 'lib/ronin/support/network/host.rb', line 440

def addresses
  @addresses ||= get_addresses
end

#change_suffix(new_suffix) ⇒ Host Also known as: change_tld

Changes the suffix of the hostname.

Examples:

host = Host.new('www.example.co.uk')
host.change_suffix('.com')
# => #<Ronin::Support::Network::Host: www.example.com>

Parameters:

  • new_suffix (String)

    The new suffix for the hostname.

Returns:

  • (Host)

    The new host object with the new suffix.

Raises:

  • (PublicSuffix::InvalidHostname)

    The hostname does not end with a valid suffix.

Since:

  • 1.0.0



312
313
314
315
316
317
318
319
320
321
# File 'lib/ronin/support/network/host.rb', line 312

def change_suffix(new_suffix)
  name, _suffix = PublicSuffix.list.split(@name)
  new_suffix    = new_suffix.to_s

  if new_suffix.start_with?('.')
    return self.class.new("#{name}#{new_suffix}")
  else
    return self.class.new("#{name}.#{new_suffix}")
  end
end

#cnameString?

Note:

This method returns memoized data.

The CNAME record for the host.

Returns:

  • (String, nil)

    The CNAME host name.

See Also:

Since:

  • 1.0.0



710
711
712
# File 'lib/ronin/support/network/host.rb', line 710

def cname
  @cname ||= get_cname
end

#domainDomain

Note:

This method returns memoized data.

Returns the associated domain for the hostname.

Examples:

host = Host.new('foo.bar.example.co.uk')
host.domain
# => #<Ronin::Support::Network::Domain: example.co.uk>

Returns:

  • (Domain)

    The domain object derived from the hostname, without any sub-domain components (ex: www).

Raises:

Since:

  • 1.0.0



265
266
267
268
269
270
271
272
273
274
275
# File 'lib/ronin/support/network/host.rb', line 265

def domain
  @domain ||= begin
    domain, suffix = PublicSuffix.list.split(@name)

    if (last_dot = domain.rindex('.'))
      domain = domain[(last_dot + 1)..]
    end

    Domain.new("#{domain}.#{suffix}")
  end
end

#each_suffix(type: nil) {|host| ... } ⇒ Enumerator

Enumerates over every hostname with a different public suffix.

Parameters:

  • type (:icann, :private, nil) (defaults to: nil)

    The optional specific type of suffixes to enumerate.

Yields:

  • (host)

    The given block will be passed each hostname with a different public suffix.

Yield Parameters:

  • host (Host)

    The new host object with a different public suffix.

Returns:

  • (Enumerator)

    If no block is given, an enumerator will be returned.

Since:

  • 1.0.0



363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/ronin/support/network/host.rb', line 363

def each_suffix(type: nil)
  return enum_for(__method__, type: type) unless block_given?

  PublicSuffix.list.each do |suffix|
    unless suffix.wildcard?
      if type.nil? || (suffix.type == type)
        yield change_suffix(suffix)
      end
    end
  end

  return nil
end

#each_tld {|host| ... } ⇒ Enumerator

Enumerates over every hostname with a different TLD.

Yields:

  • (host)

    The given block will be passed each hostname with a different TLD.

Yield Parameters:

  • host (Host)

    The new host object with a different TLD.

Returns:

  • (Enumerator)

    If no block is given, an enumerator will be returned.

Since:

  • 1.0.0



337
338
339
340
341
342
343
344
345
# File 'lib/ronin/support/network/host.rb', line 337

def each_tld
  return enum_for(__method__) unless block_given?

  TLD.list.each do |tld|
    yield change_suffix(tld)
  end

  return nil
end

#get_a_address(name = nil, **kwargs) ⇒ String?

Queries the first IPv4 address belonging to the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (String, nil)

    The first IPv4 address belonging to the host name.

See Also:

Since:

  • 1.0.0



810
811
812
813
814
815
816
# File 'lib/ronin/support/network/host.rb', line 810

def get_a_address(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_a_address(name)
end

#get_a_addresses(name = nil, **kwargs) ⇒ Array<String>

Queries all IPv4 addresses belonging to the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Array<String>)

    All of the IPv4 addresses belonging to the host name.

See Also:

Since:

  • 1.0.0



867
868
869
870
871
872
873
# File 'lib/ronin/support/network/host.rb', line 867

def get_a_addresses(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_a_addresses(name)
end

#get_a_record(name = nil, **kwargs) ⇒ Resolv::DNS::Resource::IN::A?

Queries the first A record belonging to the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Resolv::DNS::Resource::IN::A, nil)

    The first A DNS record or nil if the host name has no A records.

See Also:

Since:

  • 1.0.0



782
783
784
785
786
787
788
# File 'lib/ronin/support/network/host.rb', line 782

def get_a_record(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_a_record(name)
end

#get_a_records(name = nil, **kwargs) ⇒ Array<Resolv::DNS::Resource::IN::A>

Queries all A records belonging to the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Array<Resolv::DNS::Resource::IN::A>)

    All of the A DNS records belonging to the host name.

See Also:

Since:

  • 1.0.0



839
840
841
842
843
844
845
# File 'lib/ronin/support/network/host.rb', line 839

def get_a_records(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_a_records(name)
end

#get_aaaa_address(name = nil, **kwargs) ⇒ String?

Queries the first IPv6 address belonging to the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (String, nil)

    The first IPv6 address or nil if the host name has no IPv6 addresses.

See Also:

Since:

  • 1.0.0



926
927
928
929
930
931
932
# File 'lib/ronin/support/network/host.rb', line 926

def get_aaaa_address(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_aaaa_address(name)
end

#get_aaaa_addresses(name = nil, **kwargs) ⇒ Array<String>

Queries all IPv6 addresses belonging to the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Array<String>)

    All IPv6 addresses belonging to the host name.

See Also:

Since:

  • 1.0.0



983
984
985
986
987
988
989
# File 'lib/ronin/support/network/host.rb', line 983

def get_aaaa_addresses(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_aaaa_addresses(name)
end

#get_aaaa_record(name = nil, **kwargs) ⇒ Resolv::DNS::Resource::IN::AAAA?

Queries the first AAAA DNS records belonging to the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Resolv::DNS::Resource::IN::AAAA, nil)

    The first AAAA DNS record or nil if the host name has no AAAA records.

See Also:

Since:

  • 1.0.0



897
898
899
900
901
902
903
# File 'lib/ronin/support/network/host.rb', line 897

def get_aaaa_record(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_aaaa_record(name)
end

#get_aaaa_records(name = nil, **kwargs) ⇒ Array<Resolv::DNS::Resource::IN::AAAA>

Queries all AAAA DNS records belonging to the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Array<Resolv::DNS::Resource::IN::AAAA>)

    All of the AAAA DNS records belonging to the host name.

See Also:

Since:

  • 1.0.0



955
956
957
958
959
960
961
# File 'lib/ronin/support/network/host.rb', line 955

def get_aaaa_records(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_aaaa_records(name)
end

#get_address(**kwargs) ⇒ String? Also known as: lookup

Looks up the address of a hostname.

Examples:

host = Host.new('www.example.com')
host.get_address
# => "172.67.128.149"

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (String, nil)

    The address of the hostname.

Since:

  • 1.0.0



397
398
399
# File 'lib/ronin/support/network/host.rb', line 397

def get_address(**kwargs)
  DNS.resolver(**kwargs).get_address(@name)
end

#get_addresses(**kwargs) ⇒ Array<String>

Looks up all addresses of a hostname.

Examples:

host = Host.new('www.example.com')
host.get_addresses
# => ["104.21.2.18", "172.67.128.149"]

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

Since:

  • 1.0.0



423
424
425
# File 'lib/ronin/support/network/host.rb', line 423

def get_addresses(**kwargs)
  DNS.resolver(**kwargs).get_addresses(@name)
end

#get_any_records(name = nil, **kwargs) ⇒ Array<Resolv::DNS::Resource>

Queries all records of the host name using the ANY DNS query.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Array<Resolv::DNS::Resource>)

    All of the DNS records belonging to the host name.

See Also:

Since:

  • 1.0.0



632
633
634
635
636
637
638
# File 'lib/ronin/support/network/host.rb', line 632

def get_any_records(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_any_records(name)
end

#get_cname(name = nil, **kwargs) ⇒ String?

Queries the canonical name for the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (String, nil)

    The canonical name for the host or nil if the host has no CNAME record.

See Also:

Since:

  • 1.0.0



692
693
694
695
696
697
698
# File 'lib/ronin/support/network/host.rb', line 692

def get_cname(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_cname(name)
end

#get_cname_record(name = nil, **kwargs) ⇒ Resolv::DNS::Resource::IN::CNAME?

Queries the CNAME record for the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Resolv::DNS::Resource::IN::CNAME, nil)

    The CNAME record or nil if the host name has no CNAME record.

See Also:

Since:

  • 1.0.0



662
663
664
665
666
667
668
# File 'lib/ronin/support/network/host.rb', line 662

def get_cname_record(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_cname_record(name)
end

#get_hinfo_record(name = nil, **kwargs) ⇒ Resolv::DNS::Resource::IN::HINFO?

Queries the HINFO record for the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Resolv::DNS::Resource::IN::HINFO, nil)

    The HINFO DNS record or nil if the host name has no HINFO record.

See Also:

Since:

  • 1.0.0



736
737
738
739
740
741
742
# File 'lib/ronin/support/network/host.rb', line 736

def get_hinfo_record(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_hinfo_record(name)
end

#get_ip(**kwargs) ⇒ String?

Looks up the IPs of the host.

Examples:

host = Host.new('www.example.com')
host.get_ip
# => #<Ronin::Support::Network::IP: 172.67.128.149>

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (String, nil)

    The IP for the host.

Since:

  • 1.0.0



481
482
483
484
485
# File 'lib/ronin/support/network/host.rb', line 481

def get_ip(**kwargs)
  if (address = get_address(**kwargs))
    IP.new(address)
  end
end

#get_ips(**kwargs) ⇒ Array<IP>

Looks up all IPs for the host.

Examples:

host = Host.new('www.example.com')
host.get_ips
# => [#<Ronin::Support::Network::IP: 104.21.2.18>, #<Ronin::Support::Network::IP: 172.67.128.149>]

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Array<IP>)

    The IPs for the host.

Since:

  • 1.0.0



507
508
509
# File 'lib/ronin/support/network/host.rb', line 507

def get_ips(**kwargs)
  get_addresses(**kwargs).map { |address| IP.new(address) }
end

#get_loc_record(name = nil, **kwargs) ⇒ Resolv::DNS::Resource::LOC?

Queries the LOC (Location) DNS record of the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Resolv::DNS::Resource::LOC, nil)

    The LOC DNS record of the host name or nil if the host name has no LOC record.

See Also:

Since:

  • 1.0.0



1072
1073
1074
1075
1076
1077
1078
# File 'lib/ronin/support/network/host.rb', line 1072

def get_loc_record(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_loc_record(name)
end

#get_mailservers(**kwargs) ⇒ Array<String>

Queries the mailservers for the host name.

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Array<String>)

    The host names of the mailservers serving the given host name.

See Also:

Since:

  • 1.0.0



1156
1157
1158
# File 'lib/ronin/support/network/host.rb', line 1156

def get_mailservers(**kwargs)
  DNS.resolver(**kwargs).get_mailservers(@name)
end

#get_minfo_record(name = nil, **kwargs) ⇒ Resolv::DNS::Resource::MINFO?

Queries the MINFO (Machine-Info) DNS record of the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Resolv::DNS::Resource::MINFO, nil)

    The MINFO DNS record of the host name or nil if the host name has no MINFO record.

See Also:

Since:

  • 1.0.0



1102
1103
1104
1105
1106
1107
1108
# File 'lib/ronin/support/network/host.rb', line 1102

def get_minfo_record(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_minfo_record(name)
end

#get_mx_records(name = nil, **kwargs) ⇒ Array<Resolv::DNS::Resource::MX>

Queries all MX DNS records belonging to the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Array<Resolv::DNS::Resource::MX>)

    All MX DNS records belonging to the host name.

See Also:

Since:

  • 1.0.0



1131
1132
1133
1134
1135
1136
1137
# File 'lib/ronin/support/network/host.rb', line 1131

def get_mx_records(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_mx_records(name)
end

#get_nameservers(**kwargs) ⇒ Array<String>

Queries the nameservers for the host name.

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Array<String>)

    The host names of the nameservers serving the given host name.

See Also:

Since:

  • 1.0.0



1229
1230
1231
# File 'lib/ronin/support/network/host.rb', line 1229

def get_nameservers(**kwargs)
  DNS.resolver(**kwargs).get_nameservers(@name)
end

#get_ns_records(name = nil, **kwargs) ⇒ Array<Resolv::DNS::Resource::NS>

Queries all NS DNS records belonging to the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Array<Resolv::DNS::Resource::NS>)

    All NS DNS records belonging to the host name.

See Also:

Since:

  • 1.0.0



1204
1205
1206
1207
1208
1209
1210
# File 'lib/ronin/support/network/host.rb', line 1204

def get_ns_records(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_ns_records(name)
end

#get_record(name = nil, record_type, **kwargs) ⇒ Resolv::DNS::Resource?

Queries a single matching DNS record for the host name.

Examples:

host = Host.new('www.example.com')

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • record_type (:a, :aaaa, :any, :cname, :hinfo, :loc, :minfo, :mx, :ns, :ptr, :soa, :srv, :txt, :wks)

    The record type to query for.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Resolv::DNS::Resource, nil)

    The matching DNS records or nil if no matching DNS records could be found.

See Also:

Since:

  • 1.0.0



572
573
574
575
576
577
578
# File 'lib/ronin/support/network/host.rb', line 572

def get_record(name=nil,record_type,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_record(name,record_type)
end

#get_records(name = nil, record_type, **kwargs) ⇒ Array<Resolv::DNS::Resource>

Queries all matching DNS records for the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • record_type (:a, :aaaa, :any, :cname, :hinfo, :loc, :minfo, :mx, :ns, :ptr, :soa, :srv, :txt, :wks)

    The record type to query for.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Array<Resolv::DNS::Resource>)

    All matching DNS records.

See Also:

Since:

  • 1.0.0



604
605
606
607
608
609
610
# File 'lib/ronin/support/network/host.rb', line 604

def get_records(name=nil,record_type,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_records(name,record_type)
end

#get_soa_record(name = nil, **kwargs) ⇒ Resolv::DNS::Resource::SOA?

Queries the first SOA DNS record belonging to the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Resolv::DNS::Resource::SOA, nil)

    The first SOA DNS record for the host name or nil if the host name has no SOA records.

See Also:

Since:

  • 1.0.0



1278
1279
1280
1281
1282
1283
1284
# File 'lib/ronin/support/network/host.rb', line 1278

def get_soa_record(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_soa_record(name)
end

#get_srv_records(name = nil, **kwargs) ⇒ Array<Resolv::DNS::Resource::IN::SRV>

Queries all SRV DNS records belonging to the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Array<Resolv::DNS::Resource::IN::SRV>)

    All SRV DNS records belonging to the host name.

See Also:

Since:

  • 1.0.0



1012
1013
1014
1015
1016
1017
1018
# File 'lib/ronin/support/network/host.rb', line 1012

def get_srv_records(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_srv_records(name)
end

#get_txt_record(name = nil, **kwargs) ⇒ Resolv::DNS::Resource::TXT?

Queiries the first TXT DNS record belonging to the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Resolv::DNS::Resource::TXT, nil)

    The first TXT DNS record for the host name or nil if the host name has no TXT records.

See Also:

Since:

  • 1.0.0



1324
1325
1326
1327
1328
1329
1330
# File 'lib/ronin/support/network/host.rb', line 1324

def get_txt_record(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_txt_record(name)
end

#get_txt_records(name = nil, **kwargs) ⇒ Array<Resolv::DNS::Resource::TXT>

Queries all TXT DNS records belonging to the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Array<Resolv::DNS::Resource::TXT>)

    All of the TXT DNS records belonging to the host name.

See Also:

Since:

  • 1.0.0



1382
1383
1384
1385
1386
1387
1388
# File 'lib/ronin/support/network/host.rb', line 1382

def get_txt_records(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_txt_records(name)
end

#get_txt_string(name = nil, **kwargs) ⇒ String?

Queries the first TXT string belonging to the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (String, nil)

    The first TXT string belonging to the host name or nil if the host name has no TXT records.

See Also:

Since:

  • 1.0.0



1353
1354
1355
1356
1357
1358
1359
# File 'lib/ronin/support/network/host.rb', line 1353

def get_txt_string(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_txt_string(name)
end

#get_txt_strings(name = nil, **kwargs) ⇒ Array<String>

Queries all of the TXT string values of the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Array<String>)

    All TXT string values belonging of the host name.

See Also:

Since:

  • 1.0.0



1410
1411
1412
1413
1414
1415
1416
# File 'lib/ronin/support/network/host.rb', line 1410

def get_txt_strings(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_txt_strings(name)
end

#get_wks_records(name = nil, **kwargs) ⇒ Array<Resolv::DNS::Resource::IN::WKS>

Queries all WKS (Well-Known-Service) DNS records belonging to the host name.

Parameters:

  • name (String, nil) (defaults to: nil)

    The optional record name to query.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

  • [Array<String>, (Hash)

    a customizable set of options

  • [String, (Hash)

    a customizable set of options

Returns:

  • (Array<Resolv::DNS::Resource::IN::WKS>)

    All WKS DNS records belonging to the host name.

See Also:

Since:

  • 1.0.0



1042
1043
1044
1045
1046
1047
1048
# File 'lib/ronin/support/network/host.rb', line 1042

def get_wks_records(name=nil,**kwargs)
  name = if name then "#{name}.#{@name}"
         else         @name
         end

  DNS.resolver(**kwargs).get_wks_records(name)
end

#has_addresses?Boolean

Determines if the hostname has any addresses.

Examples:

host = Host.new('www.example.com')
host.has_addresses?
# => trun
host = Host.new('www.does-not-exist.com')
host.has_addresses?
# => false

Returns:

  • (Boolean)

Since:

  • 1.0.0



457
458
459
# File 'lib/ronin/support/network/host.rb', line 457

def has_addresses?
  !addresses.empty?
end

#has_mailservers?Boolean

Determines if the hostname has any associated mailservers?

Returns:

  • (Boolean)

Since:

  • 1.0.0



1179
1180
1181
# File 'lib/ronin/support/network/host.rb', line 1179

def has_mailservers?
  !mailservers.empty?
end

#has_nameservers?Boolean

Determines if the hostname has any associated nameservers?

Returns:

  • (Boolean)

Since:

  • 1.0.0



1252
1253
1254
# File 'lib/ronin/support/network/host.rb', line 1252

def has_nameservers?
  !nameservers.empty?
end

#hinfo_recordResolv::DNS::Resource::IN::HINFO?

Note:

This method returns memoized data.

The HINFO record for the host.

Returns:

  • (Resolv::DNS::Resource::IN::HINFO, nil)

    The HINFO DNS record or nil if the host name has no HINFO record.

See Also:

Since:

  • 1.0.0



756
757
758
# File 'lib/ronin/support/network/host.rb', line 756

def hinfo_record
  @hinfo_record ||= get_hinfo_record
end

#idn?Boolean Also known as: unicode?

Determines if the hostname is an IDN hostname.

Examples:

host = Network::Host.new("www.詹姆斯.com')
host.idn?
# => true

Returns:

  • (Boolean)

Since:

  • 1.0.0



173
174
175
# File 'lib/ronin/support/network/host.rb', line 173

def idn?
  @name !~ /\A[A-Za-z0-9._-]+\z/
end

#inspectString

Inspects the host.

Returns:

  • (String)

    The inspected host object.

Since:

  • 1.0.0



1492
1493
1494
# File 'lib/ronin/support/network/host.rb', line 1492

def inspect
  "#<#{self.class}: #{@name}>"
end

#ipIP?

The IP for the host.

Examples:

host = Host.new('www.example.com')
host.ip
# => #<Ronin::Support::Network::IP: 104.21.2.18>

Returns:

  • (IP, nil)

    The IP for the host or nil if the host has no IP addresses.

Since:

  • 1.0.0



540
541
542
# File 'lib/ronin/support/network/host.rb', line 540

def ip
  ips.first
end

#ipsArray<IP>

Note:

This method returns memoized data.

The IPs for the host.

Examples:

host = Host.new('www.example.com')
host.ips
# => [#<Ronin::Support::Network::IP: 104.21.2.18>, #<Ronin::Support::Network::IP: 172.67.128.149>]

Returns:

  • (Array<IP>)

    The IPs of the host or an empty Array if the host has no IP addresses.

Since:

  • 1.0.0



525
526
527
# File 'lib/ronin/support/network/host.rb', line 525

def ips
  @ips ||= get_ips
end

#mailserversArray<String>

Note:

This method returns memoized data.

The mailservers for the host.

Returns:

  • (Array<String>)

    The mailserver host names for the host.

See Also:

Since:

  • 1.0.0



1170
1171
1172
# File 'lib/ronin/support/network/host.rb', line 1170

def mailservers
  @mailservers ||= get_mailservers
end

#nameserversArray<String>

Note:

This method returns memoized data.

The nameservers for the host.

Returns:

  • (Array<String>)

    The nameserver IP addresses for the host.

See Also:

Since:

  • 1.0.0



1243
1244
1245
# File 'lib/ronin/support/network/host.rb', line 1243

def nameservers
  @nameservers ||= get_nameservers
end

#punycodeHost

Converts the hostname to it's punycode version.

Examples:

host = Network::Host.new("www.詹姆斯.com")
host.punycode
# => #<Ronin::Support::Network::Host: www.xn--8ws00zhy3a.com>

Returns:

  • (Host)

    The new host containing the punycode version of the hostname.

Since:

  • 1.0.0



208
209
210
# File 'lib/ronin/support/network/host.rb', line 208

def punycode
  self.class.new(DNS::IDN.to_ascii(@name))
end

#punycode?Boolean

Determines if the hostname is a punycode hostnmae.

Examples:

host = Network::Host.new("www.xn--8ws00zhy3a.com")
host.punycode?
# => true

Returns:

  • (Boolean)

Since:

  • 1.0.0



191
192
193
# File 'lib/ronin/support/network/host.rb', line 191

def punycode?
  @name.include?('xn--')
end

#registered?Boolean

Note:

This method will query 8.8.8.8 which supports ANY queries.

Determines if the host name is registered.

Examples:

host = Network::Host.new('www.example.com')
host.registered?
# => true
bad_host = Network::Host.new('foo.example.com')
bad_host.registered?
# => false

Returns:

  • (Boolean)

Since:

  • 1.0.0



1447
1448
1449
# File 'lib/ronin/support/network/host.rb', line 1447

def registered?
  !get_any_records(nameserver: '8.8.8.8').empty?
end

#soa_recordResolv::DNS::Resource::SOA?

Note:

This method returns memoized data.

The SOA record for the host.

Returns:

  • (Resolv::DNS::Resource::SOA, nil)

    The first SOA DNS record for the host name or nil if the host name has no SOA records.

See Also:

Since:

  • 1.0.0



1298
1299
1300
# File 'lib/ronin/support/network/host.rb', line 1298

def soa_record
  @soa_record ||= get_soa_record
end

#subdomain(subname) ⇒ Host

Creates a sub-domain under the hostname.

Examples:

host = Network::Host.new('example.com')
host.subdomain('www')
# => #<Ronin::Support::Network::Host: www.example.com>

Parameters:

  • subname (String)

    The sub-name to add under the hostname.

Returns:

  • (Host)

    The new sub-domain.

Since:

  • 1.0.0



291
292
293
# File 'lib/ronin/support/network/host.rb', line 291

def subdomain(subname)
  Host.new("#{subname}.#{@name}")
end

#suffixString

The public suffix of the hostname.

Examples:

host = Host.new('foo.bar.example.co.uk')
host.suffix
# => "co.uk"

Returns:

  • (String)

    The suffix of the hostname (ex: .co.uk).

Raises:

Since:

  • 1.0.0



244
245
246
# File 'lib/ronin/support/network/host.rb', line 244

def suffix
  @suffix ||= PublicSuffix.list.split(@name).last
end

#tldString

The Top-Level Domain of the hostnmae.

Examples:

host = Host.new('foo.bar.example.co.uk')
host.tld
# => "uk"

Returns:

  • (String)

    The last component of the hostname.

Raises:

Since:

  • 1.0.0



226
227
228
# File 'lib/ronin/support/network/host.rb', line 226

def tld
  @tld ||= TLD.list.split(@name).last
end

#to_sString

Converts the host to a String.

Examples:

host = Host.new('www.example.com')
host.to_s
# => "www.example.com"

Returns:

  • (String)

    The host's hostname.

Since:

  • 1.0.0



1473
1474
1475
# File 'lib/ronin/support/network/host.rb', line 1473

def to_s
  @name.to_s
end

#to_strString

Converts the host to a String.

Returns:

Since:

  • 1.0.0



1482
1483
1484
# File 'lib/ronin/support/network/host.rb', line 1482

def to_str
  @name.to_str
end

#txt_stringsArray<String>

Note:

This method returns memoized data.

The TXT strings for the host.

Returns:

  • (Array<String>)

    All TXT string values belonging of the host name.

See Also:

Since:

  • 1.0.0



1428
1429
1430
# File 'lib/ronin/support/network/host.rb', line 1428

def txt_strings
  @txt_strings ||= get_txt_strings
end

#unregistered?Boolean

Determines if the host name is not registered.

Returns:

  • (Boolean)

See Also:

Since:

  • 1.0.0



1458
1459
1460
# File 'lib/ronin/support/network/host.rb', line 1458

def unregistered?
  !registered?
end