Class: Inspec::Resources::WindowsBridge

Inherits:
BridgeDetection show all
Defined in:
lib/inspec/resources/bridge.rb

Overview

Windows Bridge select netadapter by adapter binding for windows Get-NetAdapterBinding -ComponentID ms_bridge | Get-NetAdapter RegKeys: HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlClass4D36E972-E325-11CE-BFC1-08002BE10318

Instance Attribute Summary

Attributes inherited from BridgeDetection

#inspec

Instance Method Summary collapse

Methods inherited from BridgeDetection

#initialize

Constructor Details

This class inherits a constructor from Inspec::Resources::BridgeDetection

Instance Method Details

#bridge_info(bridge_name) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/inspec/resources/bridge.rb', line 95

def bridge_info(bridge_name)
  # find all bridge adapters
  cmd = inspec.command("Get-NetAdapterBinding -ComponentID ms_bridge | Get-NetAdapter | Select-Object -Property Name, InterfaceDescription | ConvertTo-Json")

  # filter network interface
  begin
    bridges = JSON.parse(cmd.stdout)
  rescue JSON::ParserError => _e
    return nil
  end

  # ensure we have an array of groups
  bridges = [bridges] unless bridges.is_a?(Array)

  # select the requested interface
  bridges = bridges.each_with_object([]) do |adapter, adapter_collection|
    # map object
    info = {
      name: adapter["Name"],
      interfaces: nil,
    }
    adapter_collection.push(info) if info[:name].casecmp(bridge_name) == 0
  end

  return nil if bridges.empty?

  warn "[Possible Error] detected multiple bridges interfaces with the name #{bridge_name}" if bridges.size > 1
  bridges[0]
end