summaryrefslogtreecommitdiff
path: root/bin/multi-ping
blob: 7957565df90c27cde824d804fedb5998d17e6f3d (plain)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/ruby -Ilib/
#
# Usage information at the end of the script.
#

require 'getoptlong'
require 'custodian/util/ping'

#
#  Options set by the command-line.
#
help   = false
manual = false

opts = GetoptLong.new(
  ['--help',   '-h', GetoptLong::NO_ARGUMENT],
  ['--manual', '-m', GetoptLong::NO_ARGUMENT])

begin
  opts.each do |opt, _arg|
    case opt
    when '--help' then
      help = true
    when '--manual' then
      manual = true
    end
  end
rescue => err
  # any errors, show the help
  warn err.to_s
  help = true
end

#
# Show the help information.
#
if manual || help
  DATA.read.split("\n").each do |line|
    puts Regexp.last_match(1).dup if line =~ /^# ?(.*)/
  end
  exit 0
end

#
#  Get the address to ping.
#
hostname = ARGV.shift

#
#  Abort if we don't have a hostname
#
if  hostname.nil?
  puts "Usage: #{$PROGRAM_NAME} hostname"
  exit 1
end

#
#  Create the object
#
helper = Custodian::Util::Ping.new(hostname)

#
#  Ping the host, via the helper
#
if  helper.run_ping
  puts "#{hostname} - #{helper.address} - is alive."
  exit 0
else
  exit 1
end


__END__
#
# NAME
#   multi-ping - IPv4 and IPv6 ping tool
#
#
# SYNOPSIS
#  multi-ping  [ -h | --help ] [-m | --manual] hostname
#
#
# OPTIONS
#
#  -h, --help      Show a help message, and exit.
#
#  -m, --manual    Show this manual, and exit.
#
#
# ABOUT
#
#  The multi-ping tool is designed to be IPv4/IPv6-agnostic ping tool,
# which removes the need to know if you're pinging an IPv4 host or an
# IPv6 host.
#
#  The tool works by resolving the hostname specified upon the command line,
# and invoking "ping" or "ping6" upon the result - using the correct one for
# the address family which has been returned.
#
#
# AUTHOR
#
#  Steve Kemp  <steve@bytemark.co.uk>
#