title: Magic Packets and Virtual Networks
body: <p>I have 2 virtual networks, say 10.116.10.xxx and 10.116.11.xxx. I have the following code to send a magic packet:</p>
  
  <pre><code>using System;
  using System.Net;
  using System.Net.Sockets;
  using System.Globalization;
  
  public class MagicPackets:UdpClient    
  {
      public MagicPackets() : base()
      {
      }
  
      public void SetClientToBrodcastMode()    
      {
        if(this.Active)
         this.Client.SetSocketOption(SocketOptionLevel.Socket,
                                   SocketOptionName.Broadcast,0);
      }
  }
  
  public class Run
  {
       public static void Main(string[] args)
       {
          Run.WakeFunction(args[0]);
       }
  
       private static void WakeFunction(string MAC_ADDRESS)   
       {
            MagicPackets client=new MagicPackets();
            client.Connect(new 
               IPAddress(0xffffffff),
               0x2fff);
            client.SetClientToBrodcastMode();
            int counter=0;
            byte[] bytes=new byte[1024];
           //first 6 bytes should be 0xFF
           for(int y=0;y&lt;6;y++)
              bytes[counter++]=0xFF;
           //now repeate MAC 16 times
           for(int y=0;y&lt;16;y++)
           {
               int i=0;
               for(int z=0;z&lt;6;z++)
               {
                    bytes[counter++]= 
                        byte.Parse(MAC_ADDRESS.Substring(i,2),
                        NumberStyles.HexNumber);
                    i+=2;
               }
           }
  
           int reterned_value=client.Send(bytes,1024);
       }
  }
  </code></pre>
  
  <p>The code works fine when run it from a computer on the same virtual network as the computer I want to wake, but doesn't work if the computer is on the other virtual network. Any ideas why and how to fix?</p>
  
  <p>Thanks,
  Gaz</p>