minor code changes and refining
This commit is contained in:
parent
82af7a2ecb
commit
e35694352b
19
tracert.sh
19
tracert.sh
@ -28,34 +28,31 @@ timeout=2 #seconds
|
||||
i=1
|
||||
host=$1
|
||||
|
||||
while true
|
||||
do
|
||||
while true; do
|
||||
ping=$(ping -t $i -c 1 -W $timeout $host | grep -E "From|from")
|
||||
|
||||
[[ "$?" == 1 ]] && exit 1
|
||||
|
||||
if [[ $(echo $ping | cut -d ' ' -f 1) == "64" ]]
|
||||
then
|
||||
#Last hop in route
|
||||
|
||||
#For last hop in route:
|
||||
if [[ $(echo $ping | cut -d ' ' -f 4 | tr -d '():' ) =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]
|
||||
then echo -e "$i\t$(echo $ping | cut -d ' ' -f 4 | tr -d '():' )\t$(if [[ "$1" =~ [1-9][0-9].. && ${#1} == 4 ]]; then echo $1; else echo $host; fi)"
|
||||
then echo -e "$i\t$(echo $ping | cut -d ' ' -f 4 | tr -d '():' )\t$host"
|
||||
else echo -e "$i\t$(echo $ping | cut -d ' ' -f 5 | tr -d '():' )\t$(echo $ping | cut -d ' ' -f 4)"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
||||
else
|
||||
|
||||
else
|
||||
#before last hop:
|
||||
if [[ $(echo $ping | cut -d ' ' -f 3 | tr -d '():') =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]
|
||||
then echo -e "$i\t$(echo $ping | cut -d ' ' -f 3 | tr -d '():')\t$(echo $ping | cut -d ' ' -f 2)"
|
||||
then echo -e "$i\t$(echo $ping | cut -d ' ' -f 3 | tr -d '():')\t$(echo $ping | cut -d ' ' -f 2)"
|
||||
else echo -ne "$i\t$(echo $ping | cut -d ' ' -f 2)\t"
|
||||
if [[ $(echo $ping | cut -d ' ' -f 2) =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]
|
||||
then echo -e "$(host $(echo $ping | cut -d ' ' -f 2) | cut -d ' ' -f 5 | sed 's/\.$//g' | sed 's/3(NXDOMAIN)//g' | sed 's/2(SERVFAIL)//g')"
|
||||
then echo -e "$(host $(echo $ping | cut -d ' ' -f 2) | cut -d ' ' -f 5 | sed 's/\.$//g' | sed 's/3(NXDOMAIN)//g' | sed 's/2(SERVFAIL)//g')"
|
||||
else echo -e "*"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
((i++))
|
||||
done
|
||||
|
Loading…
Reference in New Issue
Block a user