Author Topic: Auto-on/off: Which port for wake-on-lan?  (Read 18482 times)

Benta

  • Calf
  • *
  • Posts: 10
Auto-on/off: Which port for wake-on-lan?
« on: August 16, 2009, 11:13:50 AM »
   

I have a linkstation mini that I like a lot.

 

One thing that I wonder about it this though:

 

The device can be put in auto-sleep mode by pushing the on-button in Auto position.

 

If I have the NAS navigator software installed on my lap top, it wakes up whenI come home.

 

In the manual it says that I can't use the Auto position and reach the device from outside if it is sleeping.

 

So I assume that the NAS navigator software is sending wake-on-lan packets to the device when I am home, right?

 

This is AFAIK the only reason why Buffalo recommends using their navigator software, despite that they are very good at sticking to open standards at Buffalo and don't invent stupid proprietary things.

 

 

Now, my router might as well send those wake on LAN packets. It should do it when I come home and when I try to access the device from outside via the web.

 

It turns out that other people thought of this. DD-WRT has a scripting function that can be used to send those packes.

 

All one would need to know is: which port to send them to on the linkstation.

 

Can Buffalo tell us this port number please?

 

The funniest thing is that Buffalo sells their own routers (they are even recommended by the DD-WRT people!) so they could very easily include this function in their own routers and use as a sales argument.

I'd buy one if they were for sale in Belgium...

 

 

 

 


Benta

  • Calf
  • *
  • Posts: 10
Re: Auto-on/off: Which port for wake-on-lan?
« Reply #1 on: August 17, 2009, 03:27:09 AM »
   

Followup to myself.

 

Here is a htread on dd-wrt about what I mean:

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

 

I also see that not only does Bufallo sell routers - they even have one model with dd-wrt preinstalled, so implementing the above script is easy if you know the port to wake up.

 

So please tell us!

 

There is probably a way to use this method to make it unnecesary to use the NASnav software to wake the NAS server up also internally, which might be good for cases where people an usupported OS on their computer. For instance, if they run Linux and still want to use the Auto-on feature on the NAS.

 


GrumpyDev

  • Calf
  • *
  • Posts: 3
Re: Auto-on/off: Which port for wake-on-lan?
« Reply #2 on: October 23, 2009, 01:58:15 PM »
   

You are correct - it is a wake-on-lan packet being used to wake the lan drive up.

 

Looking at a Wireshark trace,the magic packet is being sent from port 1172 to port 9 on the NAS drive. If you are using Windows, it may be worth you downloading a copy of Wireshark, which is a free for personal use Ethernet sniffer. Good luck.


JohnGray

  • Calf
  • *
  • Posts: 38
Re: Auto-on/off: Which port for wake-on-lan?
« Reply #3 on: October 23, 2009, 03:07:55 PM »
   

My only experience is with the LinkStation Pro, where the (Buffalo) Power Management Service (not NAS NAVI, which I have disabled)  sends a set of three WOL packets from a port number which seems irrelevant but increases sequentially to port 9, at an interval of between a very few seconds and about a minute, to keep the device awake.


GrumpyDev

  • Calf
  • *
  • Posts: 3
Re: Auto-on/off: Which port for wake-on-lan?
« Reply #4 on: October 24, 2009, 05:24:53 AM »
   I have just managed to get my LinkStation to wake up using an executable built from the wol project on Source Forge - http://sourceforge.net/projects/wake-on-lan/ - use -p 9 to send to port 9. A single wol packet wakes up the LinkStation for about five minutes so you will need to either write a script to repeatedly call the executable of change the source code. There seems to be no need to send the wol packet is groups of three - I guess that Buffalo are just trying to guard against message loss by doing this. I am running Ubuntu Linux so I can't guarantee that this will work for other OS, but I would assume that it will work the same.

sammui

  • Calf
  • *
  • Posts: 1
Re: Auto-on/off: Which port for wake-on-lan?
« Reply #5 on: October 30, 2009, 01:42:19 PM »
   

I never bother find out a better way to do WOL for my Buffalo LS Pro Duo, but I had to do that for a WDTV Live that I bought recently cuz I can't install the Navi software on it. So, I did it with a small scirpt and scheduled a cron job on my router ( ASUS WL-520gU flashed with DD-WRT v2.4 SP2)

So here is the requirement:

1) a router that's running DD-WRT v2.4 SP2 (you may need to modify the script a bit to work in older versions like v2.3 as it seems the leases file is different)

2) have the JFFS feature enabled in DD-WRT

3) your router is 24/7 on (which is I think 99.999999% true nowdays as they dont have a on/off button)

 

 

copy and past below, and save it as "wolnas" under the /jffs/usr/sbin/ directory, make sure you give it execute permission.

###################################################
# change the values in PC1, PC2, MP to the hostname of your targeted devices
# or you can add more (just make sure add to the if statement too for it to work)
###################################################

#!/bin/sh
NAS=LS-WTGL668
LEASES=/tmp/dnsmasq.leases
PC1=LivingRoomPC
PC2=RoomPC
MP=WDTVLive

NET=`nslookup $NAS | grep Server`
NET=${NET##* }
NET=${NET%.*}

while read LINE
do
HOST=${LINE% *}
HOST=${HOST##* }
if [ "$HOST" = "$PC1" -o "$HOST" = "$PC2" -o "$HOST" = "$MP" ]
then
echo "host matched $HOST"
IP=${LINE% $HOST*}
IP=${IP##* }
echo "ip of $HOST is $IP"
ONLINE=`ping -W 1 -c 1 $IP | grep 'bytes from'`
if [ -n "$ONLINE" ]
then
echo "$HOST is online"
NASLINE=`cat $LEASES | grep $NAS`
NASIP=${NASLINE% $NAS*}
NASIP=${NASIP##* }
NASMAC=${NASLINE% $NASIP*}
NASMAC=${NASMAC##* }
echo "NAS IP is $NASIP MAC is $NASMAC"
i=0
while [ $i -lt 3 ]
do
/usr/sbin/wol -i $NASIP -p 9 $NASMAC
i=$((i+1))
done
exit 0
fi
fi
done < $LEASES

then all there left to do is create a cron job entry in DD-WRT (under the "Administration tab")
* * * * * root wolnas > /tmp/wolnaslog

Now, the router that 24/7 on will be monitoring the network and does the WOL for you. Note that this will send the WOL every minute cuz I wanted it to detect my computers are online ASAP, but you can use a longer intervals by modifying the cron job schedule above.


GrumpyDev

  • Calf
  • *
  • Posts: 3
Re: Auto-on/off: Which port for wake-on-lan?
« Reply #6 on: November 14, 2009, 09:30:33 AM »
   

To change the wol program to keep looping and use the correct port by default make the following changes to the wol.c file. Code changes are bold to make them stand out.

 

Change the line:

static unsigned int port = DEFAULT_PORT;


to:

static unsigned int port = 9;


and replace the lines:

 

  if (udp_send (socketfd, host_str, portnum, m->packet, m->size))
    {
      error (0, errno, _("Cannot send magic packet for '%s' to %s:%d"),
         mac_str, host_str, portnum);
      errno = 0;
      return -1;
    }

  fprintf (stdout, _("Waking up %s"), mac_str);
  if (verbose)
    {
      fprintf (stdout, _(" with %s:%d"), host_str, portnum);
    }
  fprintf (stdout, _("...\n"));


with:

 

  /* Loop forever */
  while (-1){
    if (udp_send (socketfd, host_str, portnum, m->packet, m->size))
      {
        error (0, errno, _("Cannot send magic packet for '%s' to %s:%d"),
           mac_str, host_str, portnum);
        errno = 0;
      }

    fprintf (stdout, _("Waking up %s"), mac_str);
    if (verbose)
      {
        fprintf (stdout, _(" with %s:%d"), host_str, portnum);
      }
    fprintf (stdout, _("...\n"));

    /* Delay for 10s - value is in microseconds */
    usleep(10000000);

  }


Compile and run the program from the command line passing in the MAC address of the Buffalo drive to wake up. So if your Buffalo NAS MAC address was 11:22:33:44:55:66 you would use the command "wol 11:22:33:44:55:66" without the quotes. If using a *nix you may need to enter "./wol 11:22:33:44:55:66"


soso

  • Calf
  • *
  • Posts: 6
Re: Auto-on/off: Which port for wake-on-lan?
« Reply #7 on: December 31, 2009, 05:15:11 AM »
   

Hello,

 

is this function also available when using the linkstation with a router and an unmanaged switch?

(the router will be connected to the switch, the linkstation will be connected to the switch and the clients will also be connected to the switch)?