Class: Inspec::Resources::Interfaces::WindowsInterfaceLister

Inherits:
InterfaceLister
  • Object
show all
Defined in:
lib/inspec/resources/interfaces.rb

Instance Attribute Summary

Attributes inherited from InterfaceLister

#inspec

Instance Method Summary collapse

Methods inherited from InterfaceLister

#initialize

Constructor Details

This class inherits a constructor from Inspec::Resources::Interfaces::InterfaceLister

Instance Method Details

#scan_interfacesObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/inspec/resources/interfaces.rb', line 101

def scan_interfaces
  iface_data = []
  cmd = inspec.command("Get-NetAdapter | Select-Object -Property Name | ConvertTo-Json")
  begin
    adapter_info = JSON.parse(cmd.stdout)
    # May be a Hash if only one, or Array if multiple - normalize to Array
    adapter_info = [ adapter_info ] if adapter_info.is_a? Hash
  rescue JSON::ParserError => _e
    return nil
  end
  adapter_info.each do |info|
    iface_data << { "name" => info["Name"] }
  end
  iface_data
end