2021-09-20 09:08:45 +00:00
|
|
|
#!/bin/env bash
|
|
|
|
|
|
|
|
if [[ -z "$ping_hosts" ]];then
|
2021-09-20 14:22:10 +00:00
|
|
|
ping_hosts=("nils.lol")
|
|
|
|
else
|
|
|
|
ping_hosts=($ping_hosts)
|
2021-09-20 09:08:45 +00:00
|
|
|
fi
|
|
|
|
if [[ -z "$http_hosts" ]];then
|
2021-09-20 14:22:10 +00:00
|
|
|
http_hosts=("https://nils.lol")
|
|
|
|
else
|
|
|
|
http_hosts=($http_hosts)
|
2021-09-20 09:08:45 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
function get_code {
|
2021-09-20 14:22:10 +00:00
|
|
|
http_raw="$(curl -s -I $h | tr -d '\r')"
|
2021-09-20 15:07:45 +00:00
|
|
|
http_code="$(echo "$http_raw" | grep HTTP | cut -d " " -f 2)"
|
|
|
|
if [[ "$http_code" < 299 && "$http_code" > 199 ]];then
|
|
|
|
http_code="[\e[32m"$http_code"\e[0m"
|
|
|
|
elif [[ "$http_code" < 199 && "$http_code" > 099 ]];then
|
|
|
|
http_code="[\e[36m"$http_code"\e[0m"
|
|
|
|
elif [[ "$http_code" < 399 && "$http_code" > 299 ]];then
|
|
|
|
http_code="[\e[1;33m"$http_code"\e[0m"
|
|
|
|
elif [[ "$http_code" < 499 && "$http_code" > 399 ]];then
|
|
|
|
http_code="[\e[1;31m"$http_code"\e[0m"
|
|
|
|
elif [[ "$http_code" < 599 && "$http_code" > 499 ]];then
|
|
|
|
http_code="[\e[31m"$http_code"\e[0m"
|
|
|
|
fi
|
2021-09-21 08:26:55 +00:00
|
|
|
if [[ -z "$http_code" ]];then
|
|
|
|
http_code="[\e[1;31merror\e[0m]"
|
|
|
|
http_server=""
|
|
|
|
else
|
|
|
|
http_server=" | \e[1;34m$(echo "$http_raw" | grep -i "server" | sort -u | cut -d " " -f 2 | tr -s '\n' ' '| xargs | sed 's/ / + /g')\e[0m]"
|
|
|
|
fi
|
2021-09-20 14:22:10 +00:00
|
|
|
http_results=""$http_results"
|
2021-09-20 16:01:00 +00:00
|
|
|
$(printf "%-63s%s\n" ["\e[1;35m"$h"\e[0m"] "$http_code""$http_server")"
|
2021-09-20 09:08:45 +00:00
|
|
|
}
|
2021-09-20 10:12:41 +00:00
|
|
|
|
|
|
|
function get_ping {
|
2021-09-20 14:22:10 +00:00
|
|
|
ping_raw="$(fping -e "$p" 2> /dev/null)"
|
2021-09-20 10:12:41 +00:00
|
|
|
ping_reach="$(echo "$ping_raw" | grep -o -e "alive" -e "unreachable")"
|
2021-09-20 14:22:10 +00:00
|
|
|
if [[ "$ping_reach" == "unreachable" ]];then
|
2021-09-20 15:07:45 +00:00
|
|
|
ping_reach="[\e[32munreachable\e[0m]"
|
2021-09-20 14:22:10 +00:00
|
|
|
elif [[ "$ping_reach" == "alive" ]];then
|
2021-09-20 15:07:45 +00:00
|
|
|
ping_reach="[\e[32malive\e[0m"
|
2021-09-20 16:01:00 +00:00
|
|
|
ping_ms=" | \e[1;34m$(echo "$ping_raw" | cut -d "(" -f 2 | cut -d ")" -f 1)\e[0m]"
|
2021-09-20 14:22:10 +00:00
|
|
|
else
|
2021-09-21 08:26:55 +00:00
|
|
|
ping_reach="[\e[1;31merror\e[0m]"
|
2021-09-20 15:07:45 +00:00
|
|
|
ping_ms=""
|
2021-09-20 14:22:10 +00:00
|
|
|
fi
|
|
|
|
ping_results=""$ping_results"
|
2021-09-20 16:01:00 +00:00
|
|
|
$(printf "%-63s%s\n" ["\e[1;35m"$p"\e[0m"] "$ping_reach""$ping_ms")"
|
2021-09-20 10:12:41 +00:00
|
|
|
}
|
|
|
|
|
2021-09-20 15:18:46 +00:00
|
|
|
printf [--------------------------------------------------------------------]
|
2021-09-20 14:22:10 +00:00
|
|
|
if [[ "$ping_hosts" != "none" ]];then
|
2021-09-20 16:16:15 +00:00
|
|
|
echo ""
|
|
|
|
printf "\e[1;4mPing Hosts:\e[0m"
|
2021-09-20 14:22:10 +00:00
|
|
|
for p in "${ping_hosts[@]}";do
|
|
|
|
get_ping
|
|
|
|
done
|
2021-09-20 15:07:45 +00:00
|
|
|
echo -e "$ping_results"
|
2021-09-20 14:22:10 +00:00
|
|
|
fi
|
|
|
|
if [[ "$http_hosts" != "none" ]];then
|
2021-09-20 16:16:15 +00:00
|
|
|
echo ""
|
|
|
|
printf "\e[1;4mHTTP Hosts:\e[0m"
|
2021-09-20 14:22:10 +00:00
|
|
|
for h in "${http_hosts[@]}";do
|
|
|
|
get_code
|
|
|
|
done
|
2021-09-20 15:07:45 +00:00
|
|
|
echo -e "$http_results"
|
2021-09-20 14:22:10 +00:00
|
|
|
fi
|
2021-09-20 15:18:46 +00:00
|
|
|
echo [--------------------------------------------------------------------]
|