bb.net
Class MagicPacket

java.lang.Object
  extended by bb.net.MagicPacket

public class MagicPacket
extends Object

This class can create and send a "magic packet" to wake up another computer over the network (aka WOL).

To learn more about remote wake up, consult these links:

        http://support.intel.com/support/network/sb/CS-008459.htm
        http://www.madge.com/_assets/downloads/lsshelp8.0/LSSHelp/AdvFeat/WonLAN/WonLAN2.htm
        http://searchnetworking.techtarget.com/sDefinition/0,,sid7_gci214609,00.html
        http://www.dslreports.com/faq/wol
        http://gsd.di.uminho.pt/jpo/software/wakeonlan/mini-howto/wol-mini-howto-3.html#ss3.2
 
Note that you will likely have to configure the target computer to allow its NIC to wake up the computer. On 2004/4/2 on Lily's Win2k laptop, here is the configuration that was required:
  1. open the Network control panel
  2. right click on Local Area Connection and select Properties
  3. click on the Configure button for the network adapter
  4. In the Advanced tab, select the "Enable PME" item and set its value to Enabled
  5. In the Power Management tab, click on both options (allow device to bring computer out of standby as well as be shut down)

This class was inspired by the following magic packet programs:

        C: http://www.rom-o-matic.net/5.0.4/contrib/wakeonlan/wol.c
        Java: http://www.java-internals.com/code/
        Python: http://gsd.di.uminho.pt/jpo/software/wakeonlan/mini-howto/wolpython.txt
 

This class is multithread safe: it is immutable (both its immediate state, as well as the deep state of its fields).

Author:
Brent Boyer

Nested Class Summary
static class MagicPacket.UnitTest
          See the Overview page of the project's javadocs for a general description of this unit test class.
 
Field Summary
static int port_default
          Default port value to send the magic packet to.
 
Constructor Summary
private MagicPacket()
          This sole private constructor suppresses the default (public) constructor, ensuring non-instantiability outside of this class.
 
Method Summary
private static byte[] magicPacketData(EthernetMacAddress ethernetMacAddress)
           
static void send(EthernetMacAddress ethernetMacAddress, InetAddress inetAddress)
          Simply calls send(ethernetMacAddress, inetAddress, port_default).
static void send(EthernetMacAddress ethernetMacAddress, InetAddress inetAddress, int port)
          Sends the "magic packet" data (constructed from ethernetMacAddress) to inetAddress at port.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

port_default

public static final int port_default
Default port value to send the magic packet to.

See Also:
Port 9, or what?, How do I set up my computer for WOL?, Constant Field Values
Constructor Detail

MagicPacket

private MagicPacket()
This sole private constructor suppresses the default (public) constructor, ensuring non-instantiability outside of this class.

Method Detail

send

public static void send(EthernetMacAddress ethernetMacAddress,
                        InetAddress inetAddress)
                 throws IllegalArgumentException,
                        SocketException,
                        SecurityException,
                        IOException
Simply calls send(ethernetMacAddress, inetAddress, port_default).

Throws:
IllegalArgumentException
SocketException
SecurityException
IOException

send

public static void send(EthernetMacAddress ethernetMacAddress,
                        InetAddress inetAddress,
                        int port)
                 throws IllegalArgumentException,
                        SocketException,
                        SecurityException,
                        IOException
Sends the "magic packet" data (constructed from ethernetMacAddress) to inetAddress at port. This should wake up that computer.

Throws:
IllegalArgumentException - if ethernetMacAddress == null; inetAddress == null; port is an invalid value
SocketException - if a DatagramSocket could not be opened, or the socket could not bind to the specified local port
SecurityException - if a security manager exists and its checkListen method doesn't allow the operation
IOException - if an I/O problem occurs

magicPacketData

private static byte[] magicPacketData(EthernetMacAddress ethernetMacAddress)