Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby18/lib64/ruby/1.8
File: ping.rb
#
[0] Fix | Delete
# = ping.rb: Check a host for upness
[1] Fix | Delete
#
[2] Fix | Delete
# Author:: Yukihiro Matsumoto
[3] Fix | Delete
# Documentation:: Konrad Meyer
[4] Fix | Delete
#
[5] Fix | Delete
# Performs the function of the basic network testing tool, ping.
[6] Fix | Delete
# See: Ping.
[7] Fix | Delete
#
[8] Fix | Delete
[9] Fix | Delete
require 'timeout'
[10] Fix | Delete
require "socket"
[11] Fix | Delete
[12] Fix | Delete
#
[13] Fix | Delete
# Ping contains routines to test for the reachability of remote hosts.
[14] Fix | Delete
# Currently the only routine implemented is pingecho().
[15] Fix | Delete
#
[16] Fix | Delete
# Ping.pingecho uses a TCP echo (not an ICMP echo) to determine if the
[17] Fix | Delete
# remote host is reachable. This is usually adequate to tell that a remote
[18] Fix | Delete
# host is available to telnet, ftp, or ssh to.
[19] Fix | Delete
#
[20] Fix | Delete
# Warning: Ping.pingecho may block for a long time if DNS resolution is
[21] Fix | Delete
# slow. Requiring 'resolv-replace' allows non-blocking name resolution.
[22] Fix | Delete
#
[23] Fix | Delete
# Usage:
[24] Fix | Delete
#
[25] Fix | Delete
# require 'ping'
[26] Fix | Delete
#
[27] Fix | Delete
# puts "'jimmy' is alive and kicking" if Ping.pingecho('jimmy', 10)
[28] Fix | Delete
#
[29] Fix | Delete
module Ping
[30] Fix | Delete
[31] Fix | Delete
#
[32] Fix | Delete
# Return true if we can open a connection to the hostname or IP address
[33] Fix | Delete
# +host+ on port +service+ (which defaults to the "echo" port) waiting up
[34] Fix | Delete
# to +timeout+ seconds.
[35] Fix | Delete
#
[36] Fix | Delete
# Example:
[37] Fix | Delete
#
[38] Fix | Delete
# require 'ping'
[39] Fix | Delete
#
[40] Fix | Delete
# Ping.pingecho "google.com", 10, 80
[41] Fix | Delete
#
[42] Fix | Delete
def pingecho(host, timeout=5, service="echo")
[43] Fix | Delete
begin
[44] Fix | Delete
timeout(timeout) do
[45] Fix | Delete
s = TCPSocket.new(host, service)
[46] Fix | Delete
s.close
[47] Fix | Delete
end
[48] Fix | Delete
rescue Errno::ECONNREFUSED
[49] Fix | Delete
return true
[50] Fix | Delete
rescue Timeout::Error, StandardError
[51] Fix | Delete
return false
[52] Fix | Delete
end
[53] Fix | Delete
return true
[54] Fix | Delete
end
[55] Fix | Delete
module_function :pingecho
[56] Fix | Delete
end
[57] Fix | Delete
[58] Fix | Delete
if $0 == __FILE__
[59] Fix | Delete
host = ARGV[0]
[60] Fix | Delete
host ||= "localhost"
[61] Fix | Delete
printf("%s alive? - %s\n", host, Ping::pingecho(host, 5))
[62] Fix | Delete
end
[63] Fix | Delete
[64] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function