summaryrefslogtreecommitdiff
path: root/etc/functions/check_ping
blob: 015af0b5a4d84511923a906b968085fece24cd34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
## vim:ft=zsh
## check_ping - returns true if a host responds to ICMP echo requests
## Usage: check_ping [-6] <host>
typeset -i ipv6 ret

while [[ $1 == -* ]] {
	case $1 in
		-6) ipv6=1 ;;
	esac
	shift
}

typeset dst=$1
shift

if ((ipv6)) {
	ping6 -c 1 $dst &> /dev/null
} else {
	ping -c 1 $dst &> /dev/null
}
return