cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2456
Views
1
Helpful
2
Replies

TCL - WakeOnLan on Router

Petr Kriz
Level 1
Level 1

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:

  • Device: Cisco 1811
  • ROM: System Bootstrap, Version 12.3(8r)YH5, RELEASE SOFTWARE (fc1)
  • System image file is "flash:c181x-advipservicesk9-mz.124-24.T3.bin"

 

Thank you and best regards,

 Petr

2 Replies 2

Alexander Stevenson
Cisco Employee
Cisco Employee

 

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.

Alexander Stevenson
Cisco Employee
Cisco Employee

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