Update tracert.sh
This commit is contained in:
parent
600dfe3f99
commit
fa5c43734c
38
tracert.sh
38
tracert.sh
@ -1,19 +1,27 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#https://github.com/Projekt95/tracert
|
|
||||||
#tracert is licensed under the GNU General Public License v3.0
|
|
||||||
|
|
||||||
tabs 8
|
|
||||||
|
|
||||||
if [[ -z "$1" || "$@" == *'-h'* ]]
|
if [[ -z "$1" || "$@" == *'-h'* ]]
|
||||||
then echo -e "Usage:
|
then echo -e "Usage:
|
||||||
$(basename -- $0) [IP]
|
$(basename -- $0) [IP]
|
||||||
$(basename -- $0) [DOMAIN]
|
$(basename -- $0) [DOMAIN]
|
||||||
|
|
||||||
Github:
|
|
||||||
https://Github.com/Projekt95/tracert"; exit
|
Erstellt von Kim Drechsel"; exit
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [[ "$1" =~ [1-9][0-9].. && ${#1} == 4 ]]
|
||||||
|
then
|
||||||
|
ip1=$(echo $1 | grep -oe "^[1-9][0-9]" )
|
||||||
|
ip2=$(echo $1 | grep -oP "[1-9]$|[1-9][0-9]$" )
|
||||||
|
if [[ "$ip2" == '' ]]; then ip2=0; fi
|
||||||
|
host=10.$ip1.$ip2.1
|
||||||
|
else
|
||||||
|
host=$1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
##################################################################################
|
##################################################################################
|
||||||
##################################################################################
|
##################################################################################
|
||||||
|
|
||||||
@ -26,30 +34,34 @@ timeout=2 #seconds
|
|||||||
|
|
||||||
|
|
||||||
i=1
|
i=1
|
||||||
host=$1
|
|
||||||
|
|
||||||
while true; do
|
|
||||||
ping=$(ping -t $i -c 1 -W $timeout $host | grep -E "From|from") || exit 1
|
while true
|
||||||
|
do
|
||||||
|
ping=$(ping -t $i -c 1 -W $timeout $host | grep -E "From|from")
|
||||||
if [[ $(echo $ping | cut -d ' ' -f 1) == "64" ]]
|
if [[ $(echo $ping | cut -d ' ' -f 1) == "64" ]]
|
||||||
then
|
then
|
||||||
#For last hop in route:
|
#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}$ ]]
|
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$host"
|
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)"
|
||||||
else echo -e "$i\t$(echo $ping | cut -d ' ' -f 5 | tr -d '():' )\t$(echo $ping | cut -d ' ' -f 4)"
|
else echo -e "$i\t$(echo $ping | cut -d ' ' -f 5 | tr -d '():' )\t$(echo $ping | cut -d ' ' -f 4)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit 0
|
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}$ ]]
|
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"
|
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}$ ]]
|
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')"
|
||||||
else echo -e "*"
|
else echo -e "*"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
((i++))
|
((i++))
|
||||||
done
|
done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user