PINGHOST="172.25.0.1"

pingcheck(){
        ping -c4 $PINGHOST
        return $?
}

tuncheck(){
	iflist=$(ifconfig)
	tunif="tun0"
	case $iflist in
		*"$tunif"*)
			pingcheck
			RESULT=$?

			case $RESULT in
			        0)
			                #ping OK, do nothing
			        ;;
			        *)
			                /etc/init.d/teamviewerd start
			        ;;
			esac
		;;
		*)
			/etc/init.d/teamviewerd start
		;;
	esac
}

tuncheck
