-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from deajan/2.3
Version 2.3 release
- Loading branch information
Showing
2 changed files
with
84 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,10 @@ | |
# | ||
# uses recent versions of traceroute supporting TCP sessions | ||
# | ||
# (c) 2002-2018 Richard van den Berg <[email protected]> under the GPL | ||
# (c) 2002-2019 Richard van den Berg <[email protected]> under the GPL | ||
# http://www.gnu.org/copyleft/gpl.html | ||
# Orsiris de Jong <[email protected]> | ||
# | ||
# | ||
# 2002/12/20 v1.0 initial version | ||
# 2003/01/25 v1.1 added -c and -r options | ||
# now accepting all other tcptraceroute options | ||
|
@@ -35,9 +35,14 @@ | |
# added -Z parameter for sudo | ||
# added -M parameter for protocol | ||
# removed bc dependancy | ||
# fixed bogus -w parameter | ||
|
||
ver="v2.2" | ||
# fixed bogus -w parameter | ||
# 2019/09/25 v2.3 allow -w parameter to take floats under linux | ||
# meantime between checks is now lowered if -w parameter is less than 1 second on linux | ||
# added -o parameter, which outputs statistics similar to ping | ||
# Simpify main loop | ||
# fix ambiguous output redirect in csh for preflight check | ||
|
||
ver="v2.3" | ||
format="%Y%m%d%H%M%S" | ||
d="no" | ||
c="no" | ||
|
@@ -53,9 +58,8 @@ SUDO_COMMAND="" | |
_DEBUG=false | ||
LOCAL_OS= | ||
METHOD=tcp | ||
#WIP remove | ||
protoOptions="-T" | ||
proto=tcp | ||
summary="no" | ||
x=0 | ||
|
||
# Make sure traceroute output is language agnostic | ||
export LANG=C | ||
|
@@ -69,7 +73,7 @@ usage () { | |
echo " -d print timestamp before every result" | ||
echo " -c print a columned result line" | ||
echo " -C print in the same format as fping's -C option" | ||
echo " -w wait time in seconds (defaults to 3)" | ||
echo " -w wait time in seconds (defaults to 3). Linux supports float values, ie '.2'" | ||
echo " -r repeat every n seconds (defaults to 1)" | ||
echo " -x repeat n times (defaults to unlimited)" | ||
echo " -f first ttl (defaults to 255), see traceroute man" | ||
|
@@ -79,6 +83,7 @@ usage () { | |
echo " --sport define source port, see traceroute man" | ||
echo " -z show what command is actually sent to traceroute (debug)" | ||
echo " -Z run traceroute with sudo" | ||
echo " -o Output ping like statistics" | ||
echo | ||
echo "Default port is 80" | ||
echo "See also: man traceroute" | ||
|
@@ -98,11 +103,11 @@ getLocalOS() { | |
if grep -i Microsoft /proc/sys/kernel/osrelease > /dev/null 2>&1; then | ||
localOsVar="Microsoft" | ||
else | ||
localOsVar="$(uname -spior 2>&1)" | ||
localOsVar="`uname -spior 2>&1`" | ||
if [ $? != 0 ]; then | ||
localOsVar="$(uname -v 2>&1)" | ||
localOsVar="`uname -v 2>&1`" | ||
if [ $? != 0 ]; then | ||
localOsVar="$(uname)" | ||
localOsVar="`uname`" | ||
fi | ||
fi | ||
fi | ||
|
@@ -141,10 +146,15 @@ getLocalOS() { | |
} | ||
|
||
checkEnvironment() { | ||
if ! type traceroute > /dev/null 2>&1 ; then | ||
if ! type traceroute > /dev/null; then | ||
echo >&2 "traceroute binary not found. Please install it first" | ||
exit 1 | ||
fi | ||
|
||
if ! type awk > /dev/null; then | ||
echo >&2 "awk binary not found. Please install it first" | ||
exit 2 | ||
fi | ||
} | ||
|
||
# Check if site can be reached via TCP SYN | ||
|
@@ -171,7 +181,7 @@ _checkSite() { | |
|
||
traceRoute=`$traceRouteCommand 2>&1` | ||
if [ $? -ne 0 ]; then | ||
if [ "$(id -u)" -ne 0 ]; then | ||
if [ "`id -u`" -ne 0 ]; then | ||
echo >&2 "Unable to run '$traceRouteCommand' command. Please try run $0 with -Z parameter or 'sudo $0'" | ||
return 20 | ||
else | ||
|
@@ -238,7 +248,7 @@ _testSite() { | |
if [ "x${rtt}" != "x" -a "x${not}" = "x" ]; then | ||
echo "$myseq $nows $rtt $host" | ||
else | ||
echo "$myseq $nows $max $host" | ||
echo "$myseq $nows $maxRtt $host" | ||
fi | ||
elif [ "${C}" = "yes" ]; then | ||
if [ "$myseq" = "0" ]; then | ||
|
@@ -259,11 +269,20 @@ _testSite() { | |
else | ||
echo "${traceRoute}" | sed -e "s/^.*\*.*$/seq $myseq: no response (timeout)/" -e "s/^$ttl /seq $myseq: tcp response from/" | ||
fi | ||
|
||
echo "${traceRoute}" | awk '($1 == "*" || $2 == "*"){ exit 1 }' | ||
return $? | ||
} | ||
|
||
_quit() { | ||
echo "" | ||
echo "${pingCount} packets transmitted, `expr ${pingCount} - ${pingFailCount}` received." | ||
exit | ||
} | ||
|
||
checkEnvironment | ||
|
||
while getopts Zdhzq:w:cr:nNFSAEi:f:l:m:p:s:x:CM: opt ; do | ||
while getopts Zdhzq:w:cr:nNFSAEi:f:l:m:p:s:x:CM:o opt ; do | ||
case "$opt" in | ||
d|c|C) eval $opt="yes" ;; | ||
q|r|x) eval $opt="$OPTARG" ;; | ||
|
@@ -277,13 +296,14 @@ while getopts Zdhzq:w:cr:nNFSAEi:f:l:m:p:s:x:CM: opt ; do | |
icmp) ;; | ||
tcp) ;; | ||
udp) ;; | ||
*) | ||
*) | ||
echo >&2 "Unsupported method. Falling back to TCP" | ||
METHOD=tcp | ||
;; | ||
esac ;; | ||
Z) SUDO_COMMAND=sudo ;; | ||
z) _DEBUG=true ;; | ||
o) summary="yes" ;; | ||
?) usage; exit ;; | ||
esac | ||
done | ||
|
@@ -296,15 +316,19 @@ if [ "x$1" = "x" ]; then | |
exit | ||
fi | ||
|
||
max=$((${timeToWait} * 1000)) | ||
if [ "${summary}" = "yes" ]; then | ||
trap _quit SIGQUIT INT | ||
fi | ||
|
||
# Use awk to multiply possible float in timeToWait | ||
maxRtt=`awk 'BEGIN{printf "%.2f\n", ('${timeToWait}'*1000)}'` | ||
|
||
if [ `date +%s` != "%s" ]; then | ||
format="%s" | ||
fi | ||
|
||
getLocalOS | ||
|
||
#WIP check here | ||
if [ "$LOCAL_OS" = "BSD" ] || [ "$LOCAL_OS" = "MacOSX" ]; then | ||
METHOD_PARAMETER="-P" | ||
else | ||
|
@@ -338,37 +362,41 @@ err=$? | |
|
||
[ ${err} -gt 0 ] && exit ${err} | ||
|
||
if [ "$x" = "" ]; then | ||
while [ true ] ; do | ||
_testSite "${host}" "${port}" ${seq} ${topt} & | ||
pid=$! | ||
# if timeToWait is lower than repeatWaitTime (1 sec), repeatWaitTime should be equal to timeToWait in order to speed up pings after timeout | ||
if ! awk 'BEGIN { exit "'$repeatWaitTime'">"'$timeToWait'" }'; then | ||
repeatWaitTime=$timeToWait | ||
fi | ||
|
||
if [ "${C}" = "yes" ]; then | ||
wait $pid | ||
fi | ||
seq=`expr $seq + 1` | ||
if [ $seq -gt 0 ]; then | ||
_DEBUG=false | ||
fi | ||
sleep ${repeatWaitTime} | ||
done | ||
else | ||
while [ "$x" -gt 0 ] ; do | ||
_testSite "${host}" "${port}" ${seq} ${topt} & | ||
pid=$! | ||
pingCount=0 | ||
pingFailCount=0 | ||
|
||
if [ "${C}" = "yes" ]; then | ||
wait $pid | ||
fi | ||
seq=`expr $seq + 1` | ||
if [ $seq -gt 0 ]; then | ||
_DEBUG=false | ||
fi | ||
x=`expr $x - 1` | ||
if [ "$x" -gt 0 ]; then | ||
sleep ${repeatWaitTime} | ||
fi | ||
done | ||
fi | ||
while [ $pingCount -lt $x ] || [ $x -eq 0 ]; do | ||
result="" | ||
_testSite "${host}" "${port}" ${seq} ${topt} & | ||
pid=$! | ||
|
||
if [ "${C}" = "yes" ]; then | ||
wait $pid | ||
result=$? | ||
fi | ||
seq=`expr $seq + 1` | ||
if [ $seq -gt 0 ]; then | ||
_DEBUG=false | ||
fi | ||
if [ "$result" = "" ]; then | ||
wait $pid > /dev/null 2>&1 | ||
result=$? | ||
fi | ||
|
||
pingCount=`expr $pingCount + 1` | ||
if [ $result -ne 0 ]; then | ||
pingFailCount=`expr $pingFailCount + 1` | ||
fi | ||
if [ $pingCount -lt $x ] || [ $x -eq 0 ]; then | ||
sleep ${repeatWaitTime} | ||
fi | ||
done | ||
if [ "$summary" = "yes" ]; then | ||
_quit | ||
fi | ||
exit |