Wake-on-LAN script

I’m trying to wake up a bunch of computers with a script. None of my attempts worked, so now I’m completely clueless. :confused:

It would be a lot easier if RouterOS had support for MAC address lists.

I would be grateful if someone can give me a hint, either from a text file or from a list inside the script. I tried both approaches, but none of them work.


My list of computers look like this, but the total numbers is around 60.

PC1,AA:BB:CC:DD:EE:00
PC2,AA:BB:CC:DD:EE:01
PC3,AA:BB:CC:DD:EE:02

Idont know about your needs. but you can adopt something from my script:
/system script
add name=discovery policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=“:foreach i in=[ / ip arp find ] do={\r
\n\t:if ( [ :len [ / ip firewall address-list find list="discovered" address=[ / ip arp get $i address ] ] ] = 0 ) do={\r
\n\t\t/ ip firewall address-list add list="discovered" address=[ / ip arp get $i address ] comment=( [ / ip arp get $i interface ] . "," . [ / ip arp get $i mac-address ] )\r
\n\t\t:log info ( "discovery: found " . [ / ip arp get $i address ] . " with mac-address " . [ / ip arp get $i mac-address ] . " on interface " . [ / ip arp get $i interface ] )\r
\n\t}\r
\n} \r
\n”
add name=wake-blade01 policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=“:log info "waking blade01";/ tool wol 00:17:08:4E:EE:B4 interface=ether2; / tool wol 00:13:21:AF:D0:8A interface=ether2; / tool wol 00:13:21:
AF:E0:9A interface=ether2; / tool wol 00:13:21:AF:E0:D1 interface=ether2; / tool wol 00:17:08:4F:27:EC interface=ether2; "
add name=wake-blade02 policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=”:log info "waking blade02";/ tool wol 00:13:21:1D:5D:13 interface=ether2; / tool wol 00:13:21:AF:1A:82 interface=ether2; / tool wol 00:13:21:
B2:DC:7D interface=ether2; / tool wol 00:13:21:B2:DC:7C interface=ether2; / tool wol 00:13:21:1E:7F:14 interface=ether2; "
add name=wake-blade03 policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=“:log info "waking blade03";/ tool wol 00:13:21:1D:5D:0C interface=ether2; / tool wol 00:13:21:AE:7E:D1 interface=ether2; / tool wol 00:13:21:
AE:6E:79 interface=ether2; / tool wol 00:13:21:AE:6E:7A interface=ether2; / tool wol 00:13:21:1C:62:D0 interface=ether2; "
add name=wake-blade04 policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=”:log info "waking blade04";/ tool wol 00:17:08:4E:3F:F3 interface=ether2; / tool wol 00:13:21:AF:B0:5B interface=ether2; / tool wol 00:13:21:
AF:01:22 interface=ether2; / tool wol 00:13:21:AF:01:21 interface=ether2; / tool wol 00:17:08:4F:EC:2C interface=ether2; "
add name=wake-blade05 policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=“:log info "waking blade05";/ tool wol 00:13:21:1D:5D:19 interface=ether2; / tool wol 00:13:21:AE:7E:7B interface=ether2; / tool wol 00:13:21:
B2:0C:C3 interface=ether2; / tool wol 00:13:21:B2:0C:C2 interface=ether2; / tool wol 00:13:21:1E:6F:DC interface=ether2; "
add name=wake-blade06 policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=”:log info "waking blade06";/ tool wol 00:13:21:1D:5D:5E interface=ether2; / tool wol 00:13:21:AF:D0:34 interface=ether2; / tool wol 00:13:21:
AF:F0:A9 interface=ether2; / tool wol 00:13:21:AF:F0:AA interface=ether2; / tool wol 00:13:21:1C:62:9A interface=ether2; "
add name=wake-blade07 policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=“:log info "waking blade07";/ tool wol 00:13:21:1D:9D:8D interface=ether2; / tool wol 00:13:21:AE:7E:99 interface=ether2; / tool wol 00:13:21:
B2:0C:B3 interface=ether2; / tool wol 00:13:21:B2:0C:AE interface=ether2; / tool wol 00:13:21:1D:CB:96 interface=ether2; "
add name=wake-blade08 policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=”:log info "waking blade08";/ tool wol 00:13:21:1D:5D:69 interface=ether2; / tool wol 00:13:21:AF:18:A8 interface=ether2; / tool wol 00:13:21:
B2:EB:0E interface=ether2; / tool wol 00:13:21:B2:EB:20 interface=ether2; / tool wol 00:13:21:1C:62:8A interface=ether2; "
add name=wake-all-blades policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=
"
\n:for v from=1 to=8 do={ :foreach s in=[ / system script find name=( "wake-blade0" . $v ) ] do={ / system script run $s; :delay 500ms; } }
\n"

You could do either a file or inside of the script… which would you prefer? I can help you script either.

An example would be
:local wolInterface “ether2”
:local macList { “PCA,AA:BB:CC:DD:EE:00”;
“PCB,AA:BB:CC:DD:EE:01” }

:foreach i in $macList do={
:local macName [:pick $i 0 ([:find $i “,”])]
:local macAddress [:pick $i ([:find $i “,”]+1) [:len $i]]
/tool wol mac=$macAddress interface=$wolInterface
:put ($macName . " — " . $macAddress)
}If you want the file version post an example of your exact file format newlines and all and I can make it read from a file instead.

Thank you, I will take a look at your script.

Thank you, I really appreciate your help.

I’m not sure of the best approach, but it would be great if the MAC address is associated with a computer name. Is it possible to add each computer as a local variable?

Example:

:local PC1 “AA:BB:CC:DD:EE:00”
:local PC2 “AA:BB:CC:DD:EE:01”
:local PC3 “AA:BB:CC:DD:EE:02”

A list of computer names, and mac addresses on separate lines would be good.

Example:

PC1 AA:BB:CC:DD:EE:00
PC2 AA:BB:CC:DD:EE:01
PC3 AA:BB:CC:DD:EE:02

PC1,AA:BB:CC:DD:EE:00
PC2,AA:BB:CC:DD:EE:01
PC3,AA:BB:CC:DD:EE:02

With the script I already posted you can have names and separate lines…

The name is separated from the rest of the mac address with a comma… and the lines are separated with a "; "…
:local macList { “PCA,AA:BB:CC:DD:EE:00”;
“PCB,AA:BB:CC:DD:EE:01” }Or… just keep going…
:local macList { “PCA,AA:BB:CC:DD:EE:00”;
“PCB,AA:BB:CC:DD:EE:01”;
“PCC,AA:BB:CC:DD:EE:02” }Just make sure there are no extra spaces inside of the "s… basically the script looks for the comma… and cuts the string there into the name and the mac address.


Local variables would be a mess… because there is no good way to loop over them… and doing anything involving them would require lots of coding fo really no benefit. Just use the script I posted above as an array or we can write one to use a file with lines like
NAMEMAC-ADDRESS

-Eric

Thanks, I’ll test the script when I get to the office. I.e., when I’ve slept a few hours. :slight_smile: