Linux Bash/Shell通过爱快路由器开机远程电脑(利用主板和网卡Wake ON LAN原理)
2022/4/2 7:19:29
本文主要是介绍Linux Bash/Shell通过爱快路由器开机远程电脑(利用主板和网卡Wake ON LAN原理),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
使用说明:将以下代码保存为bootpc
,在终端中输入bootpc
命令即可,注意事先需要测试电脑主板Wake ON Lan功能是否正常,并且在爱快路由器《网络唤醒》界面添加对应设备的MAC地址;
注:以下代码中的登录验证信息和爱快路由器IP地址需要根据自己的实际情况做相应修改!
#!/bin/bash #通过爱快路由器Wake ON LAN功能开机远程电脑 #以下第一个curl命令登录信息过程已脱敏,登录鉴权请使用浏览器F12抓包即可,根据实际情况修改xxxxx具体数据 cookieFile="/tmp/cookie.tmp.$$" ##定义默认要唤醒设备的MAC地址;可通过指定$1参数覆盖 macAddress="a8:1e:47:9b:76:80" [ ! -z "$1" ] && macAddress="$1" trap "rm -f $cookieFile" 0 StampToTime(){ local connectTime if [ "$(type -t stamptotime)" = "file" ]; then connectTime=$(stamptotime "$1") else connectTime=$(date +'%Y-%m-%d %H:%M:%S' -d "1970-01-01 UTC ${1} seconds") fi echo "$connectTime" } check_jqcommand(){ [ -z "$(type -t jq)" ] && { echo -e "JSON解析工具\`jq\`命令不存在,请先安装 jq 命令行工具!" echo -e "\n官方网址:\n\thttps://stedolan.github.io/jq/" exit 1 } } check_jqcommand curl -sSf 'http://192.168.10.1/Action/login' \ -H 'Connection: keep-alive' \ -H 'Pragma: no-cache' \ -H 'Cache-Control: no-cache' \ -H 'Accept: application/json, text/plain, */*' \ -H 'DNT: 1' \ -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36' \ -H 'Content-Type: application/json;charset=UTF-8' \ -H 'Origin: http://192.168.10.1' \ -H 'Referer: http://192.168.10.1/login' \ -H 'Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,de;q=0.6,zh-TW;q=0.5' \ --data-binary '{"username":"xxxx","passwd":"xxxxxxxxxxxx","pass":"xxxxxxxxxxx","remember_password":""}' \ --cookie-jar $cookieFile >/dev/null deviceInfo=$(curl -sSf 'http://192.168.10.1/Action/call' \ -H 'Connection: keep-alive' \ -H 'Pragma: no-cache' \ -H 'Cache-Control: no-cache' \ -H 'Accept: application/json, text/plain, */*' \ -H 'DNT: 1' \ -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36' \ -H 'Content-Type: application/json;charset=UTF-8' \ -H 'Origin: http://192.168.10.1' \ -H 'Referer: http://192.168.10.1/' \ -H 'Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,de;q=0.6,zh-TW;q=0.5' \ --data-binary '{"func_name":"wakeup","action":"show","param":{"TYPE":"total,data","limit":"0,20","ORDER_BY":"","ORDER":""}}' \ -b $cookieFile) #echo "$deviceInfo"|jq -r '.' deviceId=$(echo "$deviceInfo"|jq -r '.Data.data[]|select(.mac=="'"${macAddress,,}"'")|.id|tostring') if [ -z "$deviceId" ];then echo "MAC地址错误或设备MAC不在预定义列表..." exit 0 fi echo "启动远程设备..." echo "设备MAC:$macAddress,设备ID:$deviceId ;" bootInfo=$(curl -sSf 'http://192.168.10.1/Action/call' \ -H 'Connection: keep-alive' \ -H 'Pragma: no-cache' \ -H 'Cache-Control: no-cache' \ -H 'Accept: application/json, text/plain, */*' \ -H 'DNT: 1' \ -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36' \ -H 'Content-Type: application/json;charset=UTF-8' \ -H 'Origin: http://192.168.10.1' \ -H 'Referer: http://192.168.10.1/' \ -H 'Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,de;q=0.6,zh-TW;q=0.5' \ --data-binary '{"func_name":"wakeup","action":"wake_id","param":{"id":'"${deviceId}"'}}' \ -b $cookieFile) echo "$bootInfo"|jq -r '.'
这篇关于Linux Bash/Shell通过爱快路由器开机远程电脑(利用主板和网卡Wake ON LAN原理)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-18git仓库有更新,jenkins 自动触发拉代码怎么配置的?-icode9专业技术文章分享
- 2024-12-18Jenkins webhook 方式怎么配置指定的分支?-icode9专业技术文章分享
- 2024-12-13Linux C++项目实战入门教程
- 2024-12-13Linux C++编程项目实战入门教程
- 2024-12-11Linux部署Scrapy教程:新手入门指南
- 2024-12-11怎么将在本地创建的 Maven 仓库迁移到 Linux 服务器上?-icode9专业技术文章分享
- 2024-12-10Linux常用命令
- 2024-12-06谁看谁服! Linux 创始人对于进程和线程的理解是…
- 2024-12-04操作系统教程:新手入门及初级技巧详解
- 2024-12-04操作系统入门:新手必学指南