I am trying to implement WOL using java and below is my code.
public void wakeonlan(String ipaddress, String macaddress) {
try {
byte[] macBytes = getMacBytes(macaddress);
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);
}
InetAddress address = InetAddress.getByName(ipaddress);
DatagramPacket packet = new DatagramPacket(bytes, bytes.length, address, PORT);
DatagramSocket socket = new DatagramSocket();
socket.send(packet);
socket.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
My requirement is to run a script once the PC is started.Is it possible to get the below details.
A response from the machine after it accepts the magic packet.
How long does a PC takes to startup and how long I need to wait.
Instead of sending it over the network to all machines, can I send this to the specific machine and get the response from it.