5

I have 3 IP blocks and 3 Cisco Switches. Each switch has its own IP block - 10.45.100.0/24, 10.45.101.0/24 and 10.45.102.0/24

I have got a PC on 10.45.100.0/24 block. I can wake up whole computers (with IP Address, Mac Address, Subnet, Port) in this IP block from C#.

But when I try to wake up another machine from a different IP block it does not work.

This is a Network Problem or code problem? How can I solve it?

Mark Henderson
  • 68,316
  • 31
  • 175
  • 255
Ibrahim AKGUN
  • 159
  • 1
  • 1
  • 4

6 Answers6

9

This is a fundamental problem: WOL only works inside a subnet, because a WOL magic packet isn't a valid IP packet and therefore is not routable beyound the local LAN.

The wikipedia entry outlines a solution for this problem (subnet directed broadcasts), but I've never seen this in action. Another way around the problem might be to create a WOL proxy agent that forwards WOL packets into other subnets (i.e. as a UDP packet).

Sven
  • 97,248
  • 13
  • 177
  • 225
  • So How Can i create a WOL Proxy ? Need to configure my switchs for this or any application? – Ibrahim AKGUN Jun 28 '11 at 21:19
  • A WOL proxy is easy in theory: Write a small daemon that (a) sniffs the local network and encapsulates WOL packets it detects into UDP packets that get send to its counterparts in the other two subnets and (b) if it receives such an UDP packet, it converts it into a real WOL magic packet for the local subnet. – Sven Jun 28 '11 at 21:34
3

If you have three different subnets, those subnets cannot talk to each other without a router.

This is 100% deliberate and by design.

Your Default Gateway from the machine you're trying to do the WOL from must explicity know how to get to those other subnets, or else it sends your packet out onto the internet, where it will be immediately dropped by your ISP.

So, you have two choices:

  1. Set up proper routing between the subnets
  2. Reduce your subnet mask to something like 255.255.0.0 (/16) so that all the machines are on the same subnet. I do not reccomend this, as I'm sure there's a reason that your machines are subnetted off from eachother.
Mark Henderson
  • 68,316
  • 31
  • 175
  • 255
1

One possible solution: Add a second(even a third) NIC card to your controlling PC, then configure with the other IP addresses to connect directly with the other routers. Magic packets will then pass out the associated NIC based on destination IP in the WOL command (IP, MAC, subnet, port).

user292273
  • 11
  • 1
1

WOL magic packets are subnet only as you have noticed. You can use Unicast or Subnet-Directed Broadcast depending on what you can enable in your network / router configuration:

https://technet.microsoft.com/en-us/library/bb632911.aspx

Drawbacks to this are that directed broadcasts are commonly unsupported by default due to security and performance concerns. While Unicast is commonly dependant on MAC address table memory kept in router configurations which are purged, usually in about four hours.

Jason
  • 111
  • 3
0

I have a solution, but it works for fixed IP addresses. I do not know but it might be possible to change a code to fix this for dynamic addresses.

All you need - to send a magic packet to the fixed address of your computer. I created a small utility.

My subnet is 172.17.111.0/24, packets are sent from 172.17.105.0/24

class Program
{
    static readonly Tuple<string, byte[]>[] Addr = {
        new Tuple<string, byte[]>("**-**-30-9D-98-61", new byte[] { 172, 17, 111, 91 }),
        new Tuple<string, byte[]>("**-**-D9-7B-9D-E9", new byte[] { 172, 17, 111, 70 }),
    };

    static void Main(string[] args)
    {
        var id = args.Length > 0 ? int.Parse(args[0]) : 0;

        WolClass client = new WolClass();
        client.Connect(new IPAddress(Addr[id].Item2),  0x9); 
        client.SetClientToBrodcastMode();
        //set sending bites
        int counter = 0;
        //buffer to be send
        byte[] bytes = new byte[1024];   
        //first 6 bytes should be 0xFF
        for (int y = 0; y < 6; y++)
            bytes[counter++] = 0xFF;
        //now repeate MAC 16 times
        for (int y = 0; y < 16; y++)
        {
            int i = 0;
            for (int z = 0; z < 6; z++)
            {
                bytes[counter++] = byte.Parse(Addr[id].Item1.Substring(i, 2), 
                                              NumberStyles.HexNumber);
                i += 3;
            }
        }

        //now send wake up packet
        client.Send(bytes, 1024);
    }
}

public class WolClass : UdpClient
{
    //this is needed to send broadcast packet
    public void SetClientToBrodcastMode()
    {
        if (this.Active)
            this.Client.SetSocketOption(SocketOptionLevel.Socket,
                SocketOptionName.Broadcast, 0);
    }
}
0

On Linux, I use wol (v0.7.1) to send WOL Magic Packets to a specific broadcast address:

wol -v --host=192.168.2.255 --port=9 a5:bd:dc:fe:38:8c
Waking up a5:bd:dc:fe:38:8c with 192.168.2.255:9...

My server has a separate interface on the 192.168.1.0 subnet for its public internet connection, and my wake-on-LAN nodes are on a private 192.168.2.0 subnet.

On Windows, I've used WakeMeOnLan (v1.83) to accomplish the same thing. It also supports a custom broadcast address. Versions up to 1.68 had a Use Broadcast Address According to IP Address feature, which may have been removed from later versions.

Parker
  • 763
  • 2
  • 11
  • 27