电信天翼网关4.0光猫一键重启shell脚本

理论上只要是下面这种样子的可以通用,测试用的光猫版本为TEWA-1006G

login
home

注意

  • 使用时,记得修改其中的router usr pwd变量为你的实际值。
  • 需要系统装有curl grep cut

脚本

#!/bin/sh

router='192.168.98.254'
usr='useradmin'
pwd='password'

cookie=$(curl -is 'http://'$router'/cgi-bin/luci' \
  -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \
  -H 'Accept-Language: zh,zh-CN;q=0.9,zh-HK;q=0.8,zh-TW;q=0.7,ja;q=0.6,en;q=0.5,en-GB;q=0.4,en-US;q=0.3' \
  -H 'Cache-Control: max-age=0' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Origin: http://'$router \
  -H 'Referer: http://'$router'/cgi-bin/luci' \
  -H 'Upgrade-Insecure-Requests: 1' \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.188' \
  -X 'POST' \
  -d 'username='$usr'&psd='$pwd \
  --insecure | grep -i '^Set-Cookie:' | cut -d ' ' -f2 | cut -d ';' -f1)

token=$(curl -s 'http://'$router'/cgi-bin/luci/' \
  -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \
  -H 'Accept-Language: zh,zh-CN;q=0.9,zh-HK;q=0.8,zh-TW;q=0.7,ja;q=0.6,en;q=0.5,en-GB;q=0.4,en-US;q=0.3' \
  -H 'Cache-Control: max-age=0' \
  -H 'Connection: keep-alive' \
  -H 'Cookie: '$cookie \
  -H 'Referer: http://'$router'/cgi-bin/luci' \
  -H 'Upgrade-Insecure-Requests: 1' \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.188' \
  --insecure | grep -m 1 -oE '[0-9a-f]{32}')

curl 'http://'$router'/cgi-bin/luci/admin/reboot' \
  -H 'Accept: */*' \
  -H 'Accept-Language: zh,zh-CN;q=0.9,zh-HK;q=0.8,zh-TW;q=0.7,ja;q=0.6,en;q=0.5,en-GB;q=0.4,en-US;q=0.3' \
  -H 'Connection: keep-alive' \
  -H 'Content-type: application/x-www-form-urlencoded' \
  -H 'Cookie: '$cookie \
  -H 'Origin: http://'$router \
  -H 'Referer: http://'$router'/cgi-bin/luci/' \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.188' \
  -X 'POST' \
  -d 'token='$token \
  --insecure

执行该脚本,理论上没有任何输出,即可观察到光猫自动重启。

猜你喜欢

转载自blog.csdn.net/u011570312/article/details/132128833