What's new

Help with WOL Scripting (Multiple Ports)

  • 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!

AnOutgunnedMonk

New Around Here
Hey Folks,

I've been working off of the guide to setup WOL (found here https://github.com/RMerl/asuswrt-merlin/wiki/WOL-Script-Wake-Up-Your-Webserver-On-Internet-Traffic)

I have most of the scripting working, however I'm struggling with adding a little bit of functionality. There are instructions as to how to specify a single port to allow to wake a server. I would like to expand this to allow a range of ports to wake the server, but have no practical experience with the scripting. For convenience I've included the script below.

INTERVAL=5
NUMP=3
OLD=""
TARGET=PUT YOUR INTERNAL IP ADRESS HERE!
PORT=SPECIFY YOUR PORT HERE! [THIS IS WHERE I'D LIKE TO USE MULTIPLE PORTS]
IFACE=br0
MAC=PUT YOUR MAC ADRESS HERE!
WOL=/usr/sbin/ether-wake
LOGFILE="/var/log/ether-wake.log"

while sleep $INTERVAL;do
NEW=`dmesg | awk '/ACCEPT/ && /DST='"$TARGET"'/ && /DPT='"$PORT"'/ {print }' | tail -1`
SRC=`echo $NEW | awk -F'[=| ]' '/SRC/{for(i=1;i<=NF;i++) if($i ~ /SRC/) print $(i+1)}'`
DPORT=`echo $NEW | awk -F'[=| ]' '/DPT/{for(i=1;i<=NF;i++) if($i ~ /DPT/) print $(i+1)}'`
PROTO=`echo $NEW | awk -F'[=| ]' '/PROTO/{for(i=1;i<=NF;i++) if($i ~ /PROTO/) print $(i+1)}'`

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


Thanks for everyone's help
 
I'll be interested in the more knowledgeable responses you get. I didn't think the protocol was dependent on a port, so much as the port triggering the script. To be honest, I found the wiki examples and the script way overcomplicated for anything I needed, even to wake up more than one server.

I did see from examples that you can use the OpenVPN username to trigger particular servers to wake up and not others. Haven't tried that.
 
I'll be interested in the more knowledgeable responses you get. I didn't think the protocol was dependent on a port, so much as the port triggering the script. To be honest, I found the wiki examples and the script way overcomplicated for anything I needed, even to wake up more than one server.

I did see from examples that you can use the OpenVPN username to trigger particular servers to wake up and not others. Haven't tried that.
From what I gather the actual Ether-wake is not dependent on a specific port. This script includes some logic to check the port that was reported in the log file against the port specified at the top of the script. If they match, it would proceed with sending the WoL packet. So I think the solution lies somewhere in these two lines, but I'd just need to figure out how to check against multiple port values instead of just one.

PORT=SPECIFY YOUR PORT HERE! [THIS IS WHERE I'D LIKE TO USE MULTIPLE PORTS]
NEW=`dmesg | awk '/ACCEPT/ && /DST='"$TARGET"'/ && /DPT='"$PORT"'/ {print }' | tail -1`
 

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