Skip to content

Instantly share code, notes, and snippets.

@OpenGG
Created February 14, 2023 19:07
Show Gist options
  • Save OpenGG/a99d5c45bc6a9b8f0f6b6056a9d4ae2d to your computer and use it in GitHub Desktop.
Save OpenGG/a99d5c45bc6a9b8f0f6b6056a9d4ae2d to your computer and use it in GitHub Desktop.
auto reboot modem
#!/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
#!/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