DIY一个网络唤醒小工具
By
sunbeam
at 2022-01-06 • 1人收藏 • 1332人看过
import win.ui; /*DSG{{*/ mainForm = win.form(text="WakeOnLan";right=599;bottom=399) mainForm.add( button={cls="button";text="唤醒";left=334;top=48;right=435;bottom=78;z=1}; edit={cls="edit";text="2C:56:DC:DB:71:65";left=93;top=48;right=309;bottom=78;edge=1;z=2}; static={cls="static";text="MAC地址";left=34;top=52;right=86;bottom=73;transparent=1;z=3}; static2={cls="static";left=33;top=90;right=487;bottom=114;transparent=1;z=4} ) /*}}*/ import console import wsock.udp.client; WakeUpMac = {0x2C,0x56,0xDC,0xDB,0x71,0x65};//要唤醒的电脑MAC地址,测试用 WakeHost = function(mac){ var txdata = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; for(i=1;16;1){ table.append(txdata,mac); } var buf = raw.buffer(#txdata,0); for(i=1;#txdata;1){ buf[i] = txdata[i]; } var udpClient = wsock.udp.client(); udpClient.setBroadcast(true); udpClient.sendto(buf,"255.255.255.255",9); } mainForm.button.oncommand = function(id,event){ //WakeHost(WakeUpMac);//测试用 var macstr = mainForm.edit.text; if(string.cmpMatch(macstr,"\x\x[-\:]\x\x[-\:]\x\x[-\:]\x\x[-\:]\x\x[-\:]\x\x" )){ var macarr = string.split(macstr,'-:'); for(i=1;#macarr;1){ macarr[i] = tonumber(macarr[i],16); } WakeHost(macarr); mainForm.static2.text = macstr ++ "正在唤醒" } else { //MAC字符串错误 mainForm.static2.text = "MAC地址错误" } } mainForm.show(); return win.loopMessage();
最近需要搞网络唤醒,没找到合适的工具,就打算自己动手做一个,下午搞了个demo,实测可以唤醒主机了
看论坛里没有,跟大家分享一下
3 个回复 | 最后更新于 2022-01-07
登录后方可回帖
谢谢分享, 学习了.
网络唤醒的原理是啥? 是发送任意字符到要唤醒的设备就可以了吗?