Last active
January 24, 2025 03:37
-
-
Save brwyatt/f459dc76d4fa07fe201c525711d7dcf0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
ip="" | |
ping="NO" | |
dns=() | |
timeout=1 | |
while [[ $# -gt 0 ]]; do | |
case $1 in | |
-p|--ping) | |
ping="YES" | |
shift | |
;; | |
-d|--dns) | |
dns+=("$2") | |
shift | |
shift | |
;; | |
-t|--timeout) | |
timeout="$2" | |
shift | |
shift | |
;; | |
-*|--*) | |
echo "Unknown option ${1}" | |
exit 1 | |
;; | |
*) | |
if [ "x${ip}" != "x" ]; then | |
echo "Only one IP can be defined" | |
exit 1 | |
fi | |
ip="$1" | |
shift | |
;; | |
esac | |
done | |
if [ "x${ip}" == "x" ]; then | |
echo "At least one IP must be defined" | |
exit 1 | |
fi | |
if [ "${ping}" == "YES" ]; then | |
latency=$(ping -c1 -W"${timeout}" "${ip}" | grep -iE "^rtt") | |
if [ $? -eq 0 ]; then | |
echo "on" | |
echo "${latency}" | awk 'BEGIN {FS="[/]|[ ]"} {print $8}' | |
else | |
echo -e "off" | |
echo "" | |
fi | |
fi | |
for name in "${dns[@]}"; do | |
result=$(host -ttxt -W"${timeout}" "${name}" "${ip}" | grep -iE "${name}"'\b descriptive text \"SUCCESS!\"') | |
if [[ "${result}" == *'"SUCCESS!"' ]]; then | |
echo "on" | |
else | |
echo "off" | |
fi | |
done | |
# vi: set shiftwidth=2 tabstop=2 expandtab: | |
# :indentSize=2:tabSize=2:noTabs=true: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment