01-07-2022 09:02 AM
Hello,
I have got TCL script (uploaded on flash on router) for WakeOnLan.
proc WakeOnLan { macAddr } {
set net [binary format H* [join [split $macAddr -:] ""]]
set pkt [binary format c* {0xff 0xff 0xff 0xff 0xff 0xff}]
for {set i 0} {$i < 16} {incr i} {
append pkt $net
}
# Open UDP and Send the Magic Paket.
set udpSock [udp_open]
fconfigure $udpSock -translation binary \
-remote [list 255.255.255.255 4580] \
-broadcast 1
puts $udpSock $pkt
flush $udpSock;
close $udpSock
}
if { $::argc > 0 } {
set i 1
foreach arg $::argv {
WakeOnLan $arg
incr i
}
}
When I run the script via command
tclsh flash:WakeOnLan.tcl <MacAddress>
I received an error
invalid command name "udp_open"
while executing
"udp_open"
(procedure "WakeOnLan" line 10)
invoked from within
"WakeOnLan $arg"
("foreach" body line 2)
invoked from within
"foreach arg $::argv {
WakeOnLan $arg
incr i
}"
invoked from within
"if { $::argc > 0 } {
set i 1
foreach arg $::argv {
WakeOnLan $arg
incr i
}
}"
(file "flash:WakeOnLan.tcl" line 19)
Thsi error I understand, but I can't find a solution how can I this error resolve.
Additional informations - device for testing:
Thank you and best regards,
Petr
01-20-2022 02:05 PM
Hi @Petr Kriz,
Did you happen to get that script from here? --> https://blog.ipspace.net/2011/11/sending-wake-on-lan-wol-packet-with-ios.html
If so, you missed adding broadcastAddr on line 1 and you hardcoded it into line 23. Those small differences could mean the difference.
However, I'm guessing the indentation may be the problem. I copied and pasted your code into VS Code and ran a TCL formatter I downloaded for free from the VS Code Marketplace. It adjusted your indentation. Not sure if that will fix your issue, but it's worth a try.
Formatted code:
proc WakeOnLan { macAddr } { set net [binary format H* [join [split $macAddr -:] ""]] set pkt [binary format c* {0xff 0xff 0xff 0xff 0xff 0xff}] for {set i 0} {$i < 16} {incr i} { append pkt $net } # Open UDP and Send the Magic Paket. set udpSock [udp_open] fconfigure $udpSock -translation binary \ -remote [list 255.255.255.255 4580] \ -broadcast 1 puts $udpSock $pkt flush $udpSock; close $udpSock } if { $::argc > 0 } { set i 1 foreach arg $::argv { WakeOnLan $arg incr i } }
I've attached the formatted version of the file as well. I had to make it into an .rtf file because the uploader here isn't recognizing the tcl file extension.
Hope this helps.
01-20-2022 02:09 PM
Here is a newer version of the code you're running, but without the IF function --> https://blog.protocolsyntax.com/2015/07/29/tcl-wol-on-cisco-router/
Maybe that part is the problem??
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide