public static void sendWakeOnLan(final InetAddress address, final String macStr, final int port, final int timeoutMillis, final int packets) throws IllegalArgumentException, IOException {
        if (address == null) throw new IllegalArgumentException("Address cannot be null");
        if (macStr == null) throw new IllegalArgumentException("MAC Address cannot be null");
        if (port <= 0 || port > 65535) throw new IllegalArgumentException("Invalid port " + port);
        if (packets <= 0)
            throw new IllegalArgumentException("Invalid number of packets to send " + packets);

        byte[] macBytes = MACTools.getMacBytes(macStr);
        byte[] bytes = new byte[6 + 16 * macBytes.length];
        for (int i = 0; i < 6; i++) {
            bytes[i] = (byte) 0xff;
        }
        for (int i = 6; i < bytes.length; i += macBytes.length) {
            System.arraycopy(macBytes, 0, bytes, i, macBytes.length);
        }

        DatagramPacket packet = new DatagramPacket(bytes, bytes.length, address, port);

        // Wake on lan is unreliable so best to send the packet a few times
        for (int i = 0; i < packets; i++) {
            DatagramSocket socket = new DatagramSocket();

            socket.setSoTimeout(timeoutMillis);

            socket.send(packet);
            socket.close();
        }
    }
Send a Wake-On-Lan packet

@param address       - InetAddress to send wol packet to
@param macStr        - MAC address to wake up
@param port          - port to send packet to
@param timeoutMillis - timeout (millis)
@param packets       - number of packets to send

@throws IllegalArgumentException - invalid ip or mac
@throws IOException - error sending packet
library/src/main/java/com/stealthcopter/networktools/WakeOnLan.java