Method: Windows::Exec#ping

Defined in:
lib/beaker/host/windows/exec.rb

#ping(target, attempts = 5) ⇒ Boolean

Attempt to ping the provided target hostname

Parameters:

  • target (String)

    The hostname to ping

  • attempts (Integer) (defaults to: 5)

    Amount of times to attempt ping before giving up

Returns:

  • (Boolean)

    true of ping successful, overwise false



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/beaker/host/windows/exec.rb', line 51

def ping target, attempts=5
  try = 0
  while try < attempts do
    result = exec(Beaker::Command.new("ping -n 1 #{target}"), :accept_all_exit_codes => true)
    if result.exit_code == 0
      return true
    end
    try+=1
  end
  result.exit_code == 0
end