What's new

Wake On Lan Per HTTP/HTTPS ( Script )

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

fritsp1989

Regular Contributor
Thanks for the effort you put in this project merlin.
I have a little question about the wake on lan funtions on the firmware you provide.
The webgui works exellent at this moment but it gives me to much hassle because everytime i want to visit my personal pages i need to login.
As for friends and family this is a problem because i do not provide logins to the router for them simply because i am afraid they wil screw it up.
After a long time searching on how to do it i found a couple of solutions.

1. Leave my server on for 24hs a day ( Thats gonna cost me 275 euro on yearly bases.
2. Turn on Wake On Magic Pattern , but that gives me the problem that my server doesnt mind wich port is being used and keeps on booting.

So that was not an option....

And then i found a script.
It was written for DD-WRT but i think there has to me a solution to make it work on merlin firmware.

#!/bin/sh
#Enable JFFS2 and place script in /jffs/ then run on startup in web interface.
#You can check the log from http://192.168.1.1/user/wol.html

INTERVAL=5
NUMP=3
OLD=""
PORT=80
WOLPORT=9
TARGET=192.168.1.101
BROADCAST=192.168.1.255
MAC=00:11:22:33:44:55
WOL=/usr/sbin/wol
LOGFILE="/tmp/www/wol.html"

echo "<meta http-equiv=\"refresh\" content=\"10\">" > $LOGFILE
echo "AUTO WOL Script started at" `date` "<br>" >> $LOGFILE

while sleep $INTERVAL;do
NEW=`dmesg | awk '/ACCEPT/ && /DST='"$TARGET"'/ && /DPT='"$PORT"'/ {print }' | tail -1`
SRC=`dmesg | awk -F'[=| ]' '/ACCEPT/ && /DST='"$TARGET"'/ && /DPT='"$PORT"'/ {print $7}' | tail -1`
LINE=`dmesg | awk '/ACCEPT/ && /DST='"$TARGET"'/ && /DPT='"$PORT"'/'`

if [ "$NEW" != "" -a "$NEW" != "$OLD" ]; then
if ping -qc $NUMP $TARGET >/dev/null; then
echo "NOWAKE $TARGET was accessed by $SRC and is already alive at" `date` "<br>">> $LOGFILE
else
echo "WAKE $SRC causes wake on lan at" `date` "<br>">> $LOGFILE
$WOL -i $BROADCAST -p $WOLPORT $MAC >> $LOGFILE
echo "<br>" >> $LOGFILE
sleep 5
fi
OLD=$NEW
fi
done

But how do i make this script working on Merlin WRT
 
User pages are in /tmp/var/wwwext/ in Asuswrt. However accessing a user page to trigger the wake script will also require you to login into the router, so that won't be of much help to you. That script also seems to imply that you need to enable full iptable logging, which is not recommended for performance reasons.
 
User pages are in /tmp/var/wwwext/ in Asuswrt. However accessing a user page to trigger the wake script will also require you to login into the router, so that won't be of much help to you. That script also seems to imply that you need to enable full iptable logging, which is not recommended for performance reasons.
But is there a simple solution to the ?
When someone tries to connect to port 80 8080 or 443 that the router wil wake the server ?

Thanks for your feedback
 
You could use a technique called "port knocking". Essentially you chose a port (for example 44444). Either have your router configured to log all dropped packets, or add a new iptable rules that will do a "-j logdrop" when it sees a TCP packet on port 44444.

Then, adapt the script you posted before to look for logged packets on port 44444.

Tell your friends that they need to access http://your.dyndns.org:44444/ first, wait 10-15 secs to let the server wake up, then proceed normally to the webpages stored on that server.

That way there's no login involved.
 
You could use a technique called "port knocking". Essentially you chose a port (for example 44444). Either have your router configured to log all dropped packets, or add a new iptable rules that will do a "-j logdrop" when it sees a TCP packet on port 44444.

Then, adapt the script you posted before to look for logged packets on port 44444.

Tell your friends that they need to access http://your.dyndns.org:44444/ first, wait 10-15 secs to let the server wake up, then proceed normally to the webpages stored on that server.

That way there's no login involved.


Okay thats sounds very complicated, could you post me in the right direction some wiki books or some sites where i can read about this protocol.
I googled on wake on lan knockd and all articles i find is about how to setup a nas to do it for you but i want my router to do it for me.
I am almost considering building my own router with a linux distro on it or something
 
You already got pretty much everything with that script you posted. Use port 44444 instead of 80 in that script, and make sure you enable firewall logging of rejected ports on the router webui.

To run the script, set it up as init-script. See the README included with the firmware for instructions on how to use user scripts.

EDIT: I see that script relies on ACCEPT entries in dmesg. You will have to change it to trigger on DROP instead.
 
You already got pretty much everything with that script you posted. Use port 44444 instead of 80 in that script, and make sure you enable firewall logging of rejected ports on the router webui.

To run the script, set it up as init-script. See the README included with the firmware for instructions on how to use user scripts.

EDIT: I see that script relies on ACCEPT entries in dmesg. You will have to change it to trigger on DROP instead.


Aahh damn thanks man for helping me out, But i am not a scripter i wish i was then it was already working.
Now i even have the right information but i dont know where to edit the script.
Could you edit the script for me please, i have had it i need more learning bits with thise linux boxes

Thanks i apriciated you tried to help me realy


PS i am on the openVPN Beta 2 and i cannot acces SSH or Telnet when putting them on the screen just hangs at proceeding
 
Last edited:
Aahh damn thanks man for helping me out, But i am not a scripter i wish i was then it was already working.
Now i even have the right information but i dont know where to edit the script.
Could you edit the script for me please, i have had it i need more learning bits with thise linux boxes

Thanks i apriciated you tried to help me realy


PS i am on the openVPN Beta 2 and i cannot acces SSH or Telnet when putting them on the screen just hangs at proceeding

Unfortunately I don't have the time to modify and actually test the script this week, working on the new release is taking up all my free time. Sorry :(

What do you mean by "putting them on the screen"?
 
Unfortunately I don't have the time to modify and actually test the script this week, working on the new release is taking up all my free time. Sorry :(

What do you mean by "putting them on the screen"?

Just putting them on under administration does not work the screen hangs at proceeding.
Nice to hear you are on a new firmware i am exited to see it coming!
Thanks for all the help you gave me
 
Here's how I did it:

1. Configure port forward to forward the desired port from the PC to the outside (you probably already did this).

2. Set "Logged packets type" to "Accepted" in Firewall/General.

3. Enable and format jffs Administration/System

3. After reboot (when the format of jffs is done) log in with telnet or ssh and create /jffs/scripts directory

mkdir /jffs/scripts

4. Create the script needed to wake up the computer in /jffs/scripts. This script will check the system log for packets targeted to the desired IP and, when it finds a matching line, it will send a WOL to the PC. I named the script wake.sh, but you can choose whatever name, but modify the "services-start" script accordingly. You should edit only the TARGET and MAC to match your IP.

/jffs/scripts/wake.sh:
#!/bin/sh

INTERVAL=5
NUMP=1
OLD=""
TARGET=192.168.200.3
IFACE=br0
MAC=54:04:A6:62:FF:C6
WOL=/usr/bin/ether-wake
LOGFILE="/var/log/ether-wake.log"

while sleep $INTERVAL;do
NEW=`dmesg | awk '/ACCEPT/ && /DST='"$TARGET"'/ {print }' | tail -1`
SRC=`echo $NEW | awk -F'[=| ]' '{print $8}'`
DPORT=`echo $NEW | awk -F'[=| ]' '{print $27}'`
PROTO=`echo $NEW | awk -F'[=| ]' '{print $23}'`

if [ "$NEW" != "" -a "$NEW" != "$OLD" ]; then
if ! ping -qc $NUMP $TARGET >/dev/null; then
# echo "NOWAKE $TARGET was accessed by $SRC, port $DPORT, protocol $PROTO and is already alive at" `date`>> $LOGFILE
# else
echo "WAKE $TARGET requested by $SRC, port $DPORT, protocol $PROTO at" `date`>> $LOGFILE
$WOL -i $IFACE $MAC
sleep 5
fi
OLD=$NEW
fi
done

5. Create /jffs/scripts/services-start. This script is run on every boot and it start the wake,sh script:

#!/bin/sh

#script for sending WOL packets when traffic to specified ip's
sh /jffs/scripts/wake.sh&

6. Make wake.sh and services-start executable:

chmod +x /jffs/scripts/wake.sh
chmod +x /jffs/scripts/services-start
 
Last edited:
Whoow Yeah

One word -Whooohw-

Ive been looking for a script to do this for over a month now, tried various scrits, firmwares.
I even made a router myself with an atom motherboard.
Had sleeples nights about this issue because no one seemed to be able to help me and the people that ''could'' helped me were bussy with their hard work so there was no time for them to make a script or even test it.
I managed to follow your instuctions carefully and gues what, it works awsome!
I am really happy you helped me out!
The only question that i keep in mind is how do i add ports to this script, it now works on 80 but is it possible to monitor multiple ports like 80 443 3389 for instance ?

But i stress this once more i cannot thank you enough for the work you & merlin have already done for me !
 
There is no need to configure a port because the script only checks for the TARGET IP in system log. The router will print to the system log all packets forwarded to the specified IP, regardless of the port.
In the system log you will have lines like:

Sep 16 08:33:11 kernel: ACCEPT <4>ACCEPT IN=ppp0 OUT=br0 <1>SRC=X.Y.Z.T DST=192.168.0.2 <1>LEN=129 TOS=0x00 PREC=0x00 TTL=119 ID=46122 PROTO=UDP <1>SPT=25088 DPT=9092 LEN=109

and the script only check for the DST field.
When this field matches the parameter TARGET in wake.sh script, it will send the WOL command.

If you wish to configure the script to wake the computer only for some of the forwarded ports, the you must add some "if" instructions and check if variable DPORT, taken from the logged message, matches your ports.
 
I am BANGING my head haha

Once again i am banging my head at the wall, this script worked flawlesly with the previous firmwares.
But on the new firmware i cant get this to work could someone please provide an updated script ?

Thanks in advance
 
Nothing has changed that would break this script. Make sure your scripts are still there, as the content of jffs is never guaranteed to be preserved across firmware flashes (since newer firmwares can be larger, overwriting part of the original jffs space).
 
The script is still working, but, as RMerlin said, I believe jffs was wiped out.
The same happen to me on every firmware update, but I always backup jffs to the USB disk and it's easy to restore all my scripts.
I created /jffs/scripts/services-stop with the following lines:
#!/bin/sh

#backup jffs to usb flash
cp -R /jffs /tmp/mnt/sda1/

I should check if the USB disk is on sda1, but until now I had no problems...
 
Problem solved

I dont know how i fixed it exactly but it seems that a couple of factory resets and a couple of nvram erases did the job.
At least thats what i think, because its working again there is nothing wrong with the script or firmware.
But the idea of storing scripts onto usb is a great idea anyway

Thanks
 
Hi,

i tried to configure that script. i enabled my jffs partition and created the scripts with my text editor.
but how can i copy the files to the jffs partition? how to get access to it?
thanks in advance!

Matthias
 
Hi,

i tried to configure that script. i enabled my jffs partition and created the scripts with my text editor.
but how can i copy the files to the jffs partition? how to get access to it?
thanks in advance!

Matthias

I am not at home right now so i dont know the exact steps and details
But i believe you have to download winscp en login 192.168.1.1 lgin with your username and your password from there jou can acces your jffs partition.
As soon as i have time to do it i will write some guides for you guys.
As soon as i get home i will reply with the exact steps to make the script work.
Credits to mtzo and merlin for firmware and script
 
Guide

Guide For Wake On Lan Script :

- Go to your router and login (192.168.1.1) With username and password
- Go to administration and enable JFFS partition + Format JFFS partition at next boot
- Enable SSH And Telnet
- Hit Apply and reboot your router !
- Download WINSCP http://winscp.net/download/winscp439setup.exe
- Start WINSCP and login

- Be sure to select protocol SCP, your username and password are the ones you setup for your router.

( WINSCP will give a warning about some groups missing, this is fine doesnt affect your job )

- Go to your root folder and click JFFS

- There should be a folder scripts ( if not there create it ! )

- Inside the folder JFFS right click >New>File. Name the file services-start
Paste in

#!/bin/sh

#script for sending WOL packets when traffic to specified ip's
sh /jffs/scripts/wake.sh&

- Create another file name it wake.sh and paste in
#!/bin/sh

INTERVAL=5
NUMP=1
OLD=""
TARGET=IP OF THE TARGET YOU WANT TO WAKE
IFACE=br0
MAC=MAC ADRESS OF THE TARGET YOU WANT TO WAKE
WOL=/usr/bin/ether-wake
LOGFILE="/var/log/ether-wake.log"

while sleep $INTERVAL;do
NEW=`dmesg | awk '/ACCEPT/ && /DST='"$TARGET"'/ {print }' | tail -1`
SRC=`echo $NEW | awk -F'[=| ]' '{print $8}'`
DPORT=`echo $NEW | awk -F'[=| ]' '{print $27}'`
PROTO=`echo $NEW | awk -F'[=| ]' '{print $23}'`

if [ "$NEW" != "" -a "$NEW" != "$OLD" ]; then
if ! ping -qc $NUMP $TARGET >/dev/null; then
# echo "NOWAKE $TARGET was accessed by $SRC, port $DPORT, protocol $PROTO and is already alive at" `date`>> $LOGFILE
# else
echo "WAKE $TARGET requested by $SRC, port $DPORT, protocol $PROTO at" `date`>> $LOGFILE
$WOL -i $IFACE $MAC
sleep 5
fi
OLD=$NEW
fi
done

- Put the IP and MAC in the script

Now we need to do some telnet ssh command.

Download PUTTY http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe

- Go ahead and login with putty ( 192.168.1.1 )

- Give the router username and password

Now copy and paste into putty

chmod +x /jffs/scripts/wake.sh
chmod +x /jffs/scripts/services-start

With those command you made your files executable.

We need to do one more final step !

- Login to your router webpage 192.168.1.1 > go to firewall and set logged packets to ACCEPTED
- Hit apply
Now reboot your router , Its time for some testing
 

Similar threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top