Class: Inspec::Resources::DarwinHostProvider
Instance Attribute Summary
Attributes inherited from HostProvider
#inspec
Instance Method Summary
collapse
#initialize
Instance Method Details
#ping(hostname, port = nil, proto = nil) ⇒ Object
101
102
103
104
105
106
107
108
|
# File 'lib/resources/host.rb', line 101
def ping(hostname, port = nil, proto = nil)
if proto == 'tcp'
resp = inspec.command("nc -vz -G 1 #{hostname} #{port}")
else
resp = inspec.command("ping -W 1 -c 1 #{hostname}")
end
resp.exit_status.to_i != 0 ? false : true
end
|
#resolve(hostname) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/resources/host.rb', line 110
def resolve(hostname)
cmd = inspec.command("host -t AAAA #{hostname}")
if cmd.exit_status.to_i != 0
cmd = inspec.command("host -t A #{hostname}")
end
return nil if cmd.exit_status.to_i != 0
resolve = /^.* has IPv\d address\s+(?<ip>\S+)\s*$/.match(cmd.stdout.chomp)
[resolve[1]] if resolve
end
|