diff options
Diffstat (limited to 'util')
-rwxr-xr-x | util/multi-ping | 93 |
1 files changed, 86 insertions, 7 deletions
diff --git a/util/multi-ping b/util/multi-ping index 9f60762..0d2add5 100755 --- a/util/multi-ping +++ b/util/multi-ping @@ -1,19 +1,98 @@ -#!/usr/bin/ruby +#!/usr/bin/ruby1.8 -w # -# Given a hostname, or IP address, run a ping test against it. +# NAME +# multi-ping - IPv4 and IPv6 ping tool # -# This tool looks up the IP address to determine whether to run the -# test with the system binaries "ping" or "ping6". +# SYNOPSIS +# multi-ping [ -h | --help ] [-m | --manual] hostname1 # -# Steve -# -- +# OPTIONS +# +# -h, --help Show a help message, and exit. +# +# -m, --manual Show this manual, and exit. +# +# -v, --verbose Show verbose errors +# +# 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 which has been returned. +# +# AUTHOR +# +# Steve Kemp <steve@bytemark.co.uk> # - +require 'getoptlong' require 'socket' + +# +# Options set by the command-line. These are all global. +# +$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' + $help = true + when '--manual' + $manual = true + end + end +rescue => err + # any errors, show the help + warn err.to_s + $help = true +end + + +# +# CAUTION! Here be quality kode. +# +if $manual or $help + + # Open the file, stripping the shebang line + lines = File.open(__FILE__){|fh| fh.readlines}[1..-1] + + found_synopsis = false + + lines.each do |line| + + line.chomp! + break if line.empty? + + if $help and !found_synopsis + found_synopsis = (line =~ /^#\s+SYNOPSIS\s*$/) + next + end + + puts line[2..-1].to_s + + break if $help and found_synopsis and line =~ /^#\s*$/ + + end + + exit 0 +end + + + + # # Get the address to ping. # |