This exceptional bit of code provided by Jónatan Þór Jónasson is a masterpiece. It provides the ability to send Wake On Lan commands out the local interfaces of a router to WakeUp a device. You will need a device that supports UDP Sockets, so you have to be running 15.0+ firmware.
Found this at ipSpace by Ivan Pepelnjak
ROUTER# tclsh ROUTER(tclsh)# proc WakeOnLan {broadcastAddr 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 $broadcastAddr 4580] \ -broadcast 1 puts $udpSock $pkt flush $udpSock; close $udpSock } ROUTER(tclsh)# WakeOnLan 255.255.255.255 000f13cd80a1
Hi.. I’m using your example above (I’m just using the same MAC as I’m capturing the packets) but on execution I get the following error..
Router(tcl)#WakeOnLan 255.255.255.255 000f13cd80a1
invalid command name “udp_open” ^
% Invalid input detected at ‘^’ marker.
Any hints to whats up? I’m running 15.4
My guess is your trying to run this from a catalyst switch or older Nexus switch. Unfortunately, UDP sockets are only supported on Cisco IOS and iOS XE based routers, and and the Magic packet that wakes up the device in WakeOnLan utilizes UDP datagrams.
Actually, just saw the hostname was router and I don’t believe catalyst is up to 15.4 so let me go run it on a few boxes and see if I can figure out what’s up.
It’s a 4431 ISR router.. I checked and it does support UDP sockets.
>
Okay I have a CSR in my lab ill test with… I honestly haven’t ran it on any of the IOS XE based devices yet. I’ll try this afternoon.