Class: Inspec::Resources::WindowsHostProvider
- Inherits:
-
HostProvider
- Object
- HostProvider
- Inspec::Resources::WindowsHostProvider
- Defined in:
- lib/resources/host.rb
Overview
Windows TODO: UDP is not supported yey, we need a custom ps1 script to add udp support
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
#ping(hostname, port = nil, _proto = nil) ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/resources/host.rb', line 223 def ping(hostname, port = nil, _proto = nil) # ICMP: Test-NetConnection www.microsoft.com # TCP and port: Test-NetConnection -ComputerName www.microsoft.com -RemotePort 80 request = "Test-NetConnection -ComputerName #{hostname} -WarningAction SilentlyContinue" request += " -RemotePort #{port}" unless port.nil? request += '| Select-Object -Property ComputerName, TcpTestSucceeded, PingSucceeded | ConvertTo-Json' cmd = inspec.command(request) begin ping = JSON.parse(cmd.stdout) rescue JSON::ParserError => _e return {} end { success: port.nil? ? ping['PingSucceeded'] : ping['TcpTestSucceeded'] } end |
#resolve(hostname) ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/resources/host.rb', line 240 def resolve(hostname) cmd = inspec.command("Resolve-DnsName –Type A #{hostname} | ConvertTo-Json") begin resolv = JSON.parse(cmd.stdout) rescue JSON::ParserError => _e return nil end resolv = [resolv] unless resolv.is_a?(Array) resolv.map { |entry| entry['IPAddress'] } end |