summaryrefslogtreecommitdiff
path: root/files/common/sbin/test_connectivity
blob: 6129f3208efb7a0f1e78868205a39298323dd93f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/sh

TestHosts="4.2.2.4 8.8.8.8"
PingTrials=2

iftest () {
    ifconfig $1 2>/dev/null | grep -q RUNNING
}

pingtest () {
    # TODO: replace with something parallel
    for i in $(seq 1 $PingTrials); do
	for h in $2; do
	    ping -c 1 -w 5 -I $1  $h &>/dev/null
	    if [ $? -eq 0 ]; then
		exit 0;	
	    fi
	done
    done
}

case "$1" in
    internet)
	IFace=$(uci get network.wan.ifname)
	;;
    vpn)
	IFace=tun0
	;;
    *)
	echo "Usage:
$0 <internet|vpn>" >&2
	exit 1
	;;
esac

iftest $IFace && pingtest $IFace $TestHosts
exit 1
contact: Jan Huwald // Impressum