背景

天翼网关不支持自动重启,恰好有Padavan二级路由在,所以想通过定时执行脚本重启网关。

命令解读

使用light proxy 抓包看具体哪里出错

-- 设置代理
-p -e "http_proxy=http://127.0.0.1:12888"

-- 最大重定向次数
--max-redirect=0

-- debug 请求
-d

#!/bin/bash

result=$(wget --max-redirect=0 -d --quiet \
  --method POST \
  --timeout=0 \
  --header 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \
  --header 'Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7' \
  --header 'Cache-Control: no-cache' \
  --header 'Connection: keep-alive' \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --header 'Origin: http://192.168.1.1' \
  --header 'Pragma: no-cache' \
  --header 'Referer: http://192.168.1.1/' \
  --header 'Upgrade-Insecure-Requests: 1' \
  --header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36' \
  --body-data 'username=useradmin&psd=qqq' \
  'http://192.168.1.1/cgi-bin/luci' 2>&1)

set_cookie=$(echo "$result" | grep -i 'Set-Cookie')

echo $set_cookie