File: host.rb

package info (click to toggle)
ruby-specinfra 2.89.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 2,412 kB
  • sloc: ruby: 10,338; sh: 4; makefile: 4
file content (25 lines) | stat: -rw-r--r-- 960 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Specinfra::Command::Windows::Base::Host < Specinfra::Command::Windows::Base
  class << self
    def check_is_resolvable(name, type)
      if type == "hosts"
        cmd = "@(Select-String -path (Join-Path -Path $($env:windir) -ChildPath 'system32/drivers/etc/hosts') -pattern '#{name}\\b').count -gt 0"
      else
        cmd = "@([System.Net.Dns]::GetHostAddresses('#{name}')).count -gt 0"
      end
      Backend::PowerShell::Command.new { exec cmd }
    end

    def check_is_reachable(host, port, proto, timeout)
      if port.nil?
        Backend::PowerShell::Command.new do
          exec "(New-Object System.Net.NetworkInformation.Ping).send('#{host}').Status -eq 'Success'"
        end
      else
        Backend::PowerShell::Command.new do
          using 'is_remote_port_listening.ps1'
          exec"(IsRemotePortListening -hostname #{host} -port #{port} -timeout #{timeout} -proto #{proto}) -eq $true"
        end
      end
    end
  end
end