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-11-12如何创建可引导的 ESXi USB 安装介质 (macOS, Linux, Windows)
- 2024-11-08linux的 vi编辑器中搜索关键字有哪些常用的命令和技巧?-icode9专业技术文章分享
- 2024-11-08在 Linux 的 vi 或 vim 编辑器中什么命令可以直接跳到文件的结尾?-icode9专业技术文章分享
- 2024-10-22原生鸿蒙操作系统HarmonyOS NEXT(HarmonyOS 5)正式发布
- 2024-10-18操作系统入门教程:新手必看的基本操作指南
- 2024-10-18初学者必看:操作系统入门全攻略
- 2024-10-17操作系统入门教程:轻松掌握操作系统基础知识
- 2024-09-11Linux部署Scrapy学习:入门级指南
- 2024-09-11Linux部署Scrapy:入门级指南
- 2024-08-21【Linux】分区向左扩容的方法