Created
February 14, 2023 19:07
auto reboot modem
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
#!/usr/bin/env bash | |
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | |
cd $SCRIPT_DIR | |
pwd | |
URL_204=http://connect.rom.miui.com/generate_204 | |
PING_TARGETS="baidu.com t.cn 8.8.8.8" | |
RETRY_COUNT=5 | |
CHECK_SUCCESS() { | |
local c="$?" | |
if [ "$c" == "0" ] | |
then | |
echo "success" | |
exit 0 | |
else | |
echo "fail" | |
sleep 1 | |
fi | |
} | |
# request 204 x 5 | |
for ((i=0; i<$RETRY_COUNT; i++)) | |
do | |
curl --verbose -f $URL_204 | |
CHECK_SUCCESS | |
done | |
for target in $PING_TARGETS | |
do | |
for ((i=0; i<$RETRY_COUNT; i++)) | |
do | |
ping -v -c 1 $target | |
CHECK_SUCCESS | |
done | |
done | |
. ./reboot-modem.sh |
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
#!/usr/bin/env bash | |
set -e | |
# https://www.lioat.cn | |
# https://github.com/LJea/reboot_cat | |
# https://raw.githubusercontent.com/LJea/reboot_cat/master/reboot_cat | |
ip='192.168.1.1' #光猫ip | |
user='useradmin' #光猫账号 | |
pass='XXXXXX' #光猫密码 | |
cookie=`curl -d "username=$user&psd=$pass" http://$ip/cgi-bin/luci -v 2>&1 | grep "< Set-Cookie:" | awk '{print $3}'` | |
echo cookie= $cookie | |
token=`curl --cookie "$cookie" http://$ip/cgi-bin/luci/ 2>&1 | grep "data: { token: '" | awk '{print $9}' | cut -c 2-` | |
echo token= $token | |
curl -d "token=${token%%\'*}" --cookie "$cookie" http://$ip/cgi-bin/luci/admin/reboot -v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment