Automatic WOL by monitoring IP active

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Broadcom SoC based Hardware
Author Message
nobru26
DD-WRT Novice


Joined: 24 Feb 2011
Posts: 6

PostPosted: Thu Dec 08, 2011 15:29    Post subject: Automatic WOL by monitoring IP active Reply with quote
Hello!

I'm desperately searching a script or different way to send a WOL to my server if my TV is on.

I think it could be possible to monitor the active clients on the router (my TV is in static IP) and if the IP of my TV is found, the router send over the lan a WOL for my home server.
After i have a software in the server that monitor the traffic and the clients to prevent him from hybernating, so my problem is "only" to find a way to send this packet automatically....

I'm a real newbee and don't know anything about scripting, so all help is welcome!
Thanks Laughing
Sponsor
ErMeglio
DD-WRT User


Joined: 11 Jul 2006
Posts: 104

PostPosted: Thu Dec 08, 2011 17:33    Post subject: Reply with quote
What about using cron to check, say every minute, if the tv's ip is pingable, and if it is, make the router send a wol packet to the target pc?
Check out:
WOL wiki http://www.dd-wrt.com/wiki/index.php/WOL#WOL_Scripts
CRON wiki http://www.dd-wrt.com/wiki/index.php/CRON
With Cron you do a job every minute with
Code:
*/1 * * * * script_path

remember to use crontab to modify cron jobs, so they are injected into the cron daemon and done without a reboot/restart of cron.
The dirty core of a script to check if an host is ping-able could be
Code:
ping -c 3 -w 3 192.168.3.12 | wc -l

this is to be put into an if statement that checks how many lines are there....
Try to run it in your network conditions with an unreachable host and see you are answered with a number that should be much less then the one given when using it with an active host (here 4 vs 8 for example).
Then your script could simply be
Code:
if [ "`ping -c 3 -w 3 192.168.x.y | wc -l`" -gt 6]
then
/usr/sbin/wol -i 192.168.x.255 -p PP AA:BB:CC:DD:EE:FF
fi

Where be warned that 192.168.x.255 assumes a 255.255.255.0 LAN subnet mask, if not change it accordingly.
Should be almost done Wink
nobru26
DD-WRT Novice


Joined: 24 Feb 2011
Posts: 6

PostPosted: Fri Dec 09, 2011 9:24    Post subject: Reply with quote
Hello!

Thanks for your help, i'll go to wiki trying to understand a little about CRON and scripting, i'm really not at ease with that.

My first question is about traffic, is there a problem doing a ping every minutes?
Is it not more easy to control if the ip is client of the router?
Also it's a good idea, and my TV answer to ping, so it'll be probably works.

About Cron,how i set the path? In wiki i saw differents path with differents times to execute?
Code:
*/1 * * * * script_path


And the start code of the script is

ping -c 3 -w 3 192.168.x.y | wc -l

And after i really don't understand anything
(Try to run it in your network conditions with an unreachable host and see you are answered with a number that should be much less then the one given when using it with an active host (here 4 vs 8 Question for example).
Then your script could simply be)

Code:
if [ "`ping -c 3 -w 3 192.168.x.y | wc -l`" -gt 6]
then
/usr/sbin/wol -i 192.168.x.255 -p PP AA:BB:CC:DD:EE:FF
fi Question

I'm verry sorry, i'm a newbee Confused
ErMeglio
DD-WRT User


Joined: 11 Jul 2006
Posts: 104

PostPosted: Fri Dec 09, 2011 10:35    Post subject: Reply with quote
Hey, I've tried to give you hints, now you have to do your researches, I can't teach you bash scripting here, also because I'm not able to and what I say comes from web-learning you can do yourself, too. I tried just giving hints to make your work really a lot easier. Now you have to use google if you didn't get something, this is known to be "bash scripting". See how "if" statements work. See how cron works on the web and on the wiki. They're all well-documented for sure.
The whole thing is anyway almost done, your final script should look like:
Code:
if [ "`ping -c 3 -w 3 192.168.x.y | wc -l`" -gt 6]
then
/usr/sbin/wol -i 192.168.x.255 -p PP AA:BB:CC:DD:EE:FF
fi

ONLY.
As I said
ErMeglio wrote:

Code:
ping -c 3 -w 3 192.168.3.12 | wc -l

this is to be put into an if statement that checks how many lines are there....

so, not at the beginning of a script, it's useless.
This is done in the if/then/fi code I wrote after. Look that I wrote it by hand and didn't test it, it could be erroneous.
The part where I say:
ErMeglio wrote:
Try to run it in your network conditions with an unreachable host and see you are answered with a number that should be much less then the one given when using it with an active host (here 4 vs 8 for example).

means you have to try to launch from telnet/ssh the ping commands to your active tv's ip AND to any inactive ip on YOUR network and check your numbers.
This means you have to launch ping -c 3 -w 3 192.168.x.y | wc -l where x.y is a known host and check the number it answers with (8 for me).
Then you check the same with x.y being an unreachable host in your network. My number is 4 here.
Your numbers MAY vary for a number of reasons, that's why you should do it.
What I've put in the script is the mean between 8 and 4 = 6. That script means, when this number is more than 6 (ie the tv has its active ip) then wake on lan the target pc. End of the if (fi).
onlinespending
DD-WRT User


Joined: 05 Dec 2008
Posts: 71

PostPosted: Tue Feb 21, 2012 1:55    Post subject: Reply with quote
I came up with an Automatic WOL solution about a year ago. Would be nice if this feature could be added directly to DD-WRT

http://www.dd-wrt.com/phpBB2/viewtopic.php?p=648598[/url]
flashpaul
DD-WRT Novice


Joined: 26 Feb 2012
Posts: 2

PostPosted: Sun Feb 26, 2012 11:17    Post subject: Reply with quote
I struggled with the script above , it looks like the return value from the ping command is in string format or something ,on my system it returns [4] or [8]

So the compare fails.

I am just learning bash but here is my solution :-

Code:

#!/bin/sh
ping -c 1 -t 1 192.168.1.50;
if [ $? -eq 0 ]; then
   echo "PS3 is active"
   /usr/sbin/wol -i 192.168.1.255 -p 7 xx:xx:xx:xx:xx:xx ;
else
   echo "PS3 is down" ;
fi


So once my PS3 powers on , this script wakes my media server
I just need to get cron running now which will check ping my PS3 every minute

Thanks for all the earlier suggestions , it has pointed me in the right direction.
flashpaul
DD-WRT Novice


Joined: 26 Feb 2012
Posts: 2

PostPosted: Tue Mar 13, 2012 19:26    Post subject: Reply with quote
I have amended my script a little , this is mainly due to the kids messing about with my PS3

PS3 has a static IP address and iphone is on DHCP

So now the script only turns on the media server when I am in the house as well

Quite simple really I used a second if statement to ping my iPhone , if it's present then I am home !

Code:

#!/bin/sh
ping -c 1 -t 1 192.168.1.50;
if [ $? -eq 0 ]; then
   echo "PS3 is active"
   ping -c 1 -t 1 Hoppys-iPhone;
   if [ $? -eq 0 ]; then
       /usr/sbin/wol -i 192.168.1.255 -p 7 xx:xx:xx:xx:xx:xx;
   else
   echo "iPhone is down" ;
   fi
else
   echo "PS3 is down" ;
fi
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Broadcom SoC based Hardware 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 can attach files in this forum
You can download files in this forum