WOL script help

Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking
Author Message
Nadeeja
DD-WRT Novice


Joined: 03 Dec 2017
Posts: 17

PostPosted: Sun Jan 02, 2022 11:30    Post subject: WOL script help Reply with quote
Hi,
My goal is to send a magic packet to a server when ever a specific port access is requested like in this script

https://wiki.dd-wrt.com/wiki/index.php/Useful_Scripts#Web_Server_Wake-up

But for some unknown reason this script is not working in my tp-link archer c9 router. And also enabling JFFS2 can brick my router.
https://svn.dd-wrt.com//ticket/6037
But following script seems to be working.
Code:

#!/bin/sh

 TARGET=<ip of plex server>
 MAC=<mac of plex server>
 PORTS="(32400)"

 INTERVAL=2
 NUMP=1

OLD_LC=`dmesg | wc -l | awk '{print $1}'`

 while sleep $INTERVAL
 do
     LC=`dmesg | wc -l | awk '{print $1}'`
      if [ "$LC" -ne "$OLD_LC" ]; then
         LINE=`dmesg | tail -1`
         SRC=`echo $LINE | awk '{print $8}' | sed -e "s/SRC=//g"`
         if [ "$SRC" != "" ]; then
             # Found a matching line. Try to ping the server
             RET=`ping -c $NUMP -W 1 $TARGET 2> /dev/null | awk '/packets received/ {print $4}'`
             if [ "$RET" -ne "$NUMP" ]; then
                 # Guess it's sleeping. Send WoL.
                 echo "[`date -Iseconds`] $SRC causes WOL. Line was $LINE"  >> /var/log/wol
                 /usr/sbin/wol -i <boardcast ip (typically 192.168.1.255)> -p 7 $MAC
                 sleep 10
             fi
         fi
     fi
     OLD_LC=`dmesg | wc -l | awk '{print $1}'`
 done

I obtained this from following link ;
https://www.reddit.com/r/PleX/comments/933c3y/comment/e6v6doo/?utm_source=share&utm_medium=web2x&context=3
Only thing is this code seems to be missing the part where it checks for specific port access.

So can any one help me complete this script? In current state this script keeps waking my server.
Also I don't know how to add that iptables script mentioned at the end of that post.
My firmware version is DD-WRT v3.0-r40559 std (08/06/19)

Thanks in advance
Sponsor
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12915
Location: Netherlands

PostPosted: Sun Jan 02, 2022 12:08    Post subject: Reply with quote
Unfortunately you were posting in the wrong forum.

Furthermore the build you are using is not only old and unsupported it is also a bad build, consider upgrading.
After upgrade reset to defaults and put settings in manually, never restore from a backup to a different build.

Please read the forum guidelines with helpful pointers about how to research your router, where and what firmware to download, where and how to post and many other helpful tips:
https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087

For some reading about WOL:
https://wiki.dd-wrt.com/wiki/index.php/WOL

I will transfer this thread to the appropriate forum Smile

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
Nadeeja
DD-WRT Novice


Joined: 03 Dec 2017
Posts: 17

PostPosted: Sun Jan 02, 2022 12:36    Post subject: Reply with quote
egc wrote:
Unfortunately you were posting in the wrong forum.

Furthermore the build you are using is not only old and unsupported it is also a bad build, consider upgrading.
After upgrade reset to defaults and put settings in manually, never restore from a backup to a different build.

Please read the forum guidelines with helpful pointers about how to research your router, where and what firmware to download, where and how to post and many other helpful tips:
https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087

For some reading about WOL:
https://wiki.dd-wrt.com/wiki/index.php/WOL

I will transfer this thread to the appropriate forum Smile

Thanks. Sorry for posting without reading forum guide lines.Sad
I checked for upgrades and there seems to be only one more update released after the version I'm currently using for my router.
So you think I may have messed up my previous upgrade making those script not working?
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12915
Location: Netherlands

PostPosted: Sun Jan 02, 2022 13:20    Post subject: Reply with quote
No problem we are here to help.

Since 40599 there have been more than 100 updates! (It is all in the forum guidelines)

I use WOL but I use the GUI, I use WireGuard or OpenVPN to connect to my DDWRT router and then use the GUI to activate my build system.

So I cannot comment on the script etc.

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
Nadeeja
DD-WRT Novice


Joined: 03 Dec 2017
Posts: 17

PostPosted: Sun Jan 02, 2022 17:44    Post subject: Reply with quote
Ok upgraded to latest build available for my router.
Now the version is DD-WRT v3.0-r44715 std (11/03/20) Smile
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12915
Location: Netherlands

PostPosted: Sun Jan 02, 2022 17:52    Post subject: Reply with quote
No that is not the latest build that is also an old and unsupported build.

You really should read the forum guidelines

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
eibgrad
DD-WRT Guru


Joined: 18 Sep 2010
Posts: 9157

PostPosted: Sun Jan 02, 2022 19:33    Post subject: Reply with quote
Seems to me that script could use a little cleanup. It could be simplified. It also places a burden on the router to parse the dmesg log every 2 seconds. Not the kind of thing I like to see.

Anyway, as I see it, the part I believe the OP has missed is the following.

https://www.reddit.com/r/PleX/comments/3f7d0u/plex_wol_my_setup/

Notice you're instructed to add two firewall rules to force the port forward to be logged. One if the requests comes from inside the LAN, the other if the request comes from the internet. This is unlike the original script which told you to turn ALL logging on. And if all other logging is OFF, and you find a log entry in dmesg, then has to be the one you triggered (w/ the port you specified) in the firewall rules.

IOW, the PORTS variable was there in the original script because everything was being logged. You *had* to search for it to be sure the port forward of interest was triggered. But as modified, the PORTS variable is irrelevant and can be deleted.

_________________
ddwrt-ovpn-split-basic.sh (UPDATED!) * ddwrt-ovpn-split-advanced.sh (UPDATED!) * ddwrt-ovpn-client-killswitch.sh * ddwrt-ovpn-client-watchdog.sh * ddwrt-ovpn-remote-access.sh * ddwrt-ovpn-client-backup.sh * ddwrt-mount-usb-drives.sh * ddwrt-blacklist-domains.sh * ddwrt-wol-port-forward.sh * ddwrt-dns-monitor.sh (NEW!)
kernel-panic69
DD-WRT Guru


Joined: 08 May 2018
Posts: 14246
Location: Texas, USA

PostPosted: Sun Jan 02, 2022 20:58    Post subject: Reply with quote
Nadeeja wrote:
But for some unknown reason this script is not working in my tp-link archer c9 router.
My firmware version is DD-WRT v3.0-r40559 std (08/06/19)

egc wrote:
Since 40599 there have been more than 100 updates! (It is all in the forum guidelines)

Nadeeja wrote:
Ok upgraded to latest build available for my router.
Now the version is DD-WRT v3.0-r44715 std (11/03/20) Smile

egc wrote:
No that is not the latest build that is also an old and unsupported build.

You really should read the forum guidelines



Current release as of this post (but I didn't know which version you had, so):

https://ftp.dd-wrt.com/dd-wrtv2/downloads/betas/2021/12-30-2021-r47942/tplink_archer-c9v1/

https://ftp.dd-wrt.com/dd-wrtv2/downloads/betas/2021/12-30-2021-r47942/tplink_archer-c9v2/

https://ftp.dd-wrt.com/dd-wrtv2/downloads/betas/2021/12-30-2021-r47942/tplink_archer-c9v3/

https://ftp.dd-wrt.com/dd-wrtv2/downloads/betas/2021/12-30-2021-r47942/tplink_archer-c9v4/

_________________
"Life is but a fleeting moment, a vapor that vanishes quickly; All is vanity"
Contribute To DD-WRT
Pogo - A minimal level of ability is expected and needed...
DD-WRT Releases 2023 (PolitePol)
DD-WRT Releases 2023 (RSS Everything)

----------------------
Linux User #377467 counter.li.org / linuxcounter.net
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum