Created
June 25, 2017 14:55
-
-
Save zaftzaft/299041cb101ee8ec711a5a6731b96503 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
| # netcheck --dns google.com@8.8.8.8 --ping 8.8.8.8 --dhcp 192.168.0.1 | |
| for OPT in "$@" | |
| do | |
| case "$OPT" in | |
| --dns) | |
| d=`echo $2 | sed -e "s/@/ /"` | |
| addr=`echo $d | cut -f1 -d " "` | |
| server=`echo $d | cut -f2 -d " "` | |
| res=`dig $addr A +timeout=1 @$server` | |
| if [ $? -eq 0 ];then | |
| echo netcheck_dns\{addr=\"$addr\",status=\"result\"\} 1 | |
| else | |
| echo netcheck_dns\{addr=\"$addr\",status=\"result\"\} 0 | |
| fi | |
| shift 2 | |
| ;; | |
| --ping) | |
| addr=$2 | |
| res=`ping -c 1 $addr -w 1` | |
| if [ $? -eq 0 ]; then | |
| rtt=`echo $res | grep "time=[0-9]*.[0-9]*" -o | sed -e "s/time=//"` | |
| echo netcheck_ping\{addr=\"$addr\",status=\"result\"\} 1 | |
| echo netcheck_ping\{addr=\"$addr\",status=\"rtt\"\} $rtt | |
| else | |
| echo netcheck_ping\{addr=\"$addr\",status=\"result\"\} 0 | |
| fi | |
| shift 2 | |
| ;; | |
| --dhcp) | |
| addr=$2 | |
| dhcping -s $addr -q | |
| shift 2 | |
| ;; | |
| esac | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment