Community discussions

MikroTik App
 
Borage
Member Candidate
Member Candidate
Topic Author
Posts: 170
Joined: Sun Sep 26, 2004 10:19 pm

Wake-on-LAN script

Sat Nov 16, 2013 8:54 pm

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

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
 
samsung172
Forum Guru
Forum Guru
Posts: 1193
Joined: Sat Apr 04, 2009 3:45 am
Location: Østfold - Norway
Contact:

Re: Wake-on-LAN script

Tue Nov 19, 2013 3:00 am

Idont know about your needs. but you can adopt something from my script:

ros code

/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"
 
efaden
Forum Guru
Forum Guru
Posts: 1708
Joined: Sat Mar 30, 2013 1:55 am
Location: New York, USA

Re: Wake-on-LAN script

Tue Nov 19, 2013 3:07 am

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

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
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

ros code

: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.
 
Borage
Member Candidate
Member Candidate
Topic Author
Posts: 170
Joined: Sun Sep 26, 2004 10:19 pm

Re: Wake-on-LAN script

Wed Nov 20, 2013 1:43 am

Idont know about your needs. but you can adopt something from my script:
Thank you, I will take a look at your script.
You could do either a file or inside of the script... which would you prefer? I can help you script either.
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"
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.
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
 
efaden
Forum Guru
Forum Guru
Posts: 1708
Joined: Sat Mar 30, 2013 1:55 am
Location: New York, USA

Re: Wake-on-LAN script

Wed Nov 20, 2013 1:58 am

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 "; \"...

ros code

:local macList { "PCA,AA:BB:CC:DD:EE:00"; \
    "PCB,AA:BB:CC:DD:EE:01" }
Or... just keep going...

ros code

: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
NAME<SPACE>MAC-ADDRESS

-Eric
 
Borage
Member Candidate
Member Candidate
Topic Author
Posts: 170
Joined: Sun Sep 26, 2004 10:19 pm

Re: Wake-on-LAN script

Wed Nov 20, 2013 2:26 am

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