Created
September 24, 2016 20:26
-
-
Save ali-essam/80b58ea170051a96108b5f320754564f to your computer and use it in GitHub Desktop.
bash script to restart zte h108n router
This file contains 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
#!/bin/bash | |
USER='yourusername' | |
PASS='yourpassword' | |
function login { | |
local __resultvar=$1 | |
local FRMTOKEN=$(curl -s 'http://192.168.1.1/' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,ar;q=0.6,ru;q=0.4' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.92 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Connection: keep-alive' --compressed | grep "(\"Frm_Logintoken\").value = \"[0-9]*\"" | grep -o "[0-9]*") | |
echo "Frm_Logintoken=$FRMTOKEN" | |
curl -s 'http://192.168.1.1/' -H 'Origin: http://192.168.1.1' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8,ar;q=0.6,ru;q=0.4' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.92 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Referer: http://192.168.1.1/' -H 'Connection: keep-alive' --data "frashnum=&action=login&Frm_Logintoken=$FRMTOKEN&Username=$USER&Password=$PASS" --compressed > /dev/null | |
local RET=$(curl -s 'http://192.168.1.1/template.gch?pid=1002&nextpage=status_dev_info_t.gch' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,ar;q=0.6,ru;q=0.4' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.92 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://192.168.1.1/start.ghtml' -H 'Connection: keep-alive' --compressed | grep "session_token = \"[0-9]*\"" | grep -o "[0-9]*") | |
eval $__resultvar="'$RET'" | |
} | |
echo 'Logging In...' | |
login TOKEN | |
TM=1 | |
while [ -z "$TOKEN" ] | |
do | |
echo "Retrying Login In $TM seconds..." | |
login TOKEN | |
sleep $TM | |
TM=$((TM * 2)) | |
done | |
echo "Token=$TOKEN" | |
curl -s 'http://192.168.1.1/getpage.gch?pid=1002&nextpage=manager_dev_conf_t.gch' -H 'Origin: http://192.168.1.1' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8,ar;q=0.6,ru;q=0.4' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.92 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Referer: http://192.168.1.1/getpage.gch?pid=1002&nextpage=manager_dev_conf_t.gch' -H 'Connection: keep-alive' --data "IF_ACTION=devrestart&IF_ERRORSTR=SUCC&IF_ERRORPARAM=SUCC&IF_ERRORTYPE=-1&flag=1&_SESSION_TOKEN=$TOKEN" --compressed > /dev/null | |
echo 'Restarting The Freakin Router....' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment