#!/bin/sh

LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
#GOOGLE=$(ping -4 www.gstatic.com -c 1 -w 5| sed '1{s/[^(]*(//;s/).*//;q}')

#iptables -t nat -I OUTPUT -p tcp -d $GOOGLE -j REDIRECT --to-port 7070

#sleep 3

/usr/bin/wget --spider --quiet --tries=1 --timeout=3 www.gstatic.com/generate_204

if [ "$?" == "0" ]; then
	echo '['$LOGTIME'] V2Ray No Problem.'
else
	/usr/bin/wget --spider --quiet --tries=1 --timeout=3 www.baidu.com
	if [ "$?" == "0" ]; then
		echo '['$LOGTIME'] Problem decteted, restarting V2Ray...'
		/etc/init.d/v2raypro restart
	else
		echo '['$LOGTIME'] Network Problem. Do nothing.'
	fi
fi

#sleep 3

#iptables -t nat -D OUTPUT -p tcp -d $GOOGLE -j REDIRECT --to-port 7070
