Class: Inspec::Resources::UnixHostProvider
- Inherits:
-
HostProvider
- Object
- HostProvider
- Inspec::Resources::UnixHostProvider
- Defined in:
- lib/resources/host.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from HostProvider
Instance Method Summary collapse
Methods inherited from HostProvider
#initialize, #missing_requirements
Constructor Details
This class inherits a constructor from Inspec::Resources::HostProvider
Instance Method Details
#resolve_with_dig(hostname) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/resources/host.rb', line 148 def resolve_with_dig(hostname) addresses = [] # look for IPv6 addresses cmd = inspec.command("dig +short AAAA #{hostname}") cmd.stdout.lines.each do |line| matched = line.chomp.match(Resolv::IPv6::Regex) addresses << matched.to_s unless matched.nil? end # look for IPv4 addresses cmd = inspec.command("dig +short A #{hostname}") cmd.stdout.lines.each do |line| matched = line.chomp.match(Resolv::IPv4::Regex) addresses << matched.to_s unless matched.nil? end addresses.empty? ? nil : addresses end |
#resolve_with_getent(hostname) ⇒ Object
168 169 170 171 172 173 174 175 176 |
# File 'lib/resources/host.rb', line 168 def resolve_with_getent(hostname) # TODO: we rely on getent hosts for now, but it prefers to return IPv6, only then IPv4 cmd = inspec.command("getent hosts #{hostname}") return nil if cmd.exit_status.to_i != 0 # extract ip adress resolve = /^\s*(?<ip>\S+)\s+(.*)\s*$/.match(cmd.stdout.chomp) [resolve[1]] if resolve end |