Method: Inspec::Resources::WindowsHostProvider#resolve

Defined in:
lib/inspec/resources/host.rb

#resolve(hostname) ⇒ Object



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/inspec/resources/host.rb', line 312

def resolve(hostname)
  addresses = []
  # -Type A is the DNS query for IPv4 server Address.
  cmd = inspec.command("Resolve-DnsName –Type A #{hostname} | ConvertTo-Json")
  begin
    resolve_ipv4 = JSON.parse(cmd.stdout)
  rescue JSON::ParserError => _e
    return nil
  end

  # Append the ipv4 addresses
  resolve_ipv4 = [resolve_ipv4] unless resolve_ipv4.is_a?(Array)
  resolve_ipv4.each { |entry| addresses << entry["IPAddress"] }

  # -Type AAAA is the DNS query for IPv6 server Address.
  cmd = inspec.command("Resolve-DnsName –Type AAAA #{hostname} | ConvertTo-Json")
  begin
    resolve_ipv6 = JSON.parse(cmd.stdout)
  rescue JSON::ParserError => _e
    return nil
  end

  # Append the ipv6 addresses
  resolve_ipv6 = [resolve_ipv6] unless resolve_ipv6.is_a?(Array)
  resolve_ipv6.each { |entry| addresses << entry["IPAddress"] }

  addresses
end