auto WOL on port-specific traffic, shellscript help needed

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


Joined: 29 Dec 2009
Posts: 12

PostPosted: Thu May 11, 2017 14:40    Post subject: auto WOL on port-specific traffic, shellscript help needed Reply with quote
Hi all!
I hope this landed in the correct category, otherwize i am very sorry for my mistake!

First some details:
dd-wrt router (asus rt-n13u b1), running v3.0-r31221std
Server: Windows 10 pc, running Plex Media Center and has WOL enabled, tested and confirmed working.
Clients: laptop (wlan), android phone (wlan&mobile network).

Im trying to have the router detect plex-traffic to the server and if the server doesnt answer, a WOL packet should be sent.

Ive been following a number of different tutorials to set this up and so far ive enabled logging on the router, level HIGH and for both accept, dropped and rejected.

The http://192.168.1.1/Syslog.asp page shows all the traffic correctly, but the script log; http://192.168.1.1/user/wol.html does not show each plex connect.

Ive been trying to understand why syslog shows the traffic but not WOL log and ive found that plex uses a number of different ports, not just the default one.


i do think i have a "solution", but i lack the skills to implement it..

the wol-script does define PORT= but i think that it shouldnt be a single port, but a number of them.
So instead of "PORT=32400" it should be something like: "PORT=32400,32410,32412,32413,32414,1900" and so on, but i simply do not grasp how to change the script accordingly.

So does anybody have the skills to modify the script for me?
Any new traffic to any of the listed ports should trigger the "ping server, if no reply, send WOL" feature.

the ports i need are 32400(default), 32410, 32412, 32413, 32414(port range for GDM network discovery) and 1900(DLNA).

The script im using is copied from a unknown source (might be here at dd-wrt.com, might be some other tut, its been to many google searches to be sure..).


Code:
#!/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=1
PINGTIME=1
OLD=""
PORT=32400
WOLPORT=9
TARGET=192.168.1.25
BROADCAST=192.168.1.255
MAC=(CORRECT MAC ADDRESS, DELETED for privacy)
WOL=/usr/sbin/wol
LOGFILE="/tmp/www/wol.html"

echo "<meta http-equiv=\"refresh\" content=\"10\">" > $LOGFILE
echo "["`date`"] AUTO WOL Script started. <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 -qw $PINGTIME $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 1                                                                                 
   fi                                                                                         
   OLD=$NEW                                                                                 
fi                                                                                                                                                                               
done
Sponsor
Patrick1610
DD-WRT Novice


Joined: 24 Jul 2017
Posts: 17

PostPosted: Mon Jul 24, 2017 22:27    Post subject: Reply with quote
Have you had any luck so far?

I want to implement a similar script to wol Plex, but my dd-wrt router is a secondary router. Really hoping to find some info!
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