Sep 24

Wake-on-LAN is an Ethernet computer networking standard that allows a computer to be turned on or woken up by a network message. The message is usually sent by a simple program executed on another computer on the local area network.

BIOS Setup

You first need to enable WOL in your bios. This might be a Wake on LAN setting under power management, or it might be something like “Allow power from S5 by PME”. S5 is a power management state and PME is Power Management Event.

Computer Setup

You need to make sure you allow your network device to wake up your pc. In windows you can do this through the device manager for your network adapter. If you edit the properties for your network card (Control Panel > Device Manager > Network Adapters > Your Ethernet card > Properties > Power Management) – you can check a box to ‘Allow this device to wake up the computer’ and you can force it only to allow WOL magic packets to wake up the pc.

Routers

If your pc is behind a router, then you will need to forward all requests to port 9 to your pc that you want to wake up. Some routers allow you to assign applications to certain devices, and you may see ‘Wake On LAN’ as one of the applications.

Java code to wake up your pc

Below is some java code that you can use to wake up your pc using wake on lan. You will need to know your IP address and the MAC address of your network card.

package com.devedup.net;

import org.apache.log4j.Logger;

import java.io.*;
import java.net.*;

/**
 * Used for waking up computers
 *
 * @author dave
 * @since 9 Apr 2009 08:00:04
 */
public class WakeOnLAN {

    private final static Logger logger = Logger.getLogger(WakeOnLAN.class);

    public static final int PORT = 9;

    public static void main(String[] args) {

        if (args.length != 2) {
            logger.info("Usage: java WakeOnLan <broadcast-ip> <mac-address>");
            logger.info(
                "Example: java WakeOnLan 192.168.0.255 00:0D:61:08:22:4A");
            logger.info(
                "Example: java WakeOnLan 192.168.0.255 00-0D-61-08-22-4A");
            System.exit(1);
        }

        String ipStr = args[0];
        String macStr = args[1];

        try {
            wakeup(ipStr, macStr);
        } catch (Exception e) {
            logger.info("Failed to send Wake-on-LAN packet: + e");
            System.exit(1);
        }

    }

    /**
     * Send a Wake On LAN magic packet to ip and mac address specifed
     *
     * @param ip
     * @param macAddress
     */
    public static void wakeup(String ip, String macAddress) {
        if (ip == null || ip.length() < 1)
            throw new IllegalArgumentException(
                          "ip address cannot be null or blank");
        if (macAddress == null || macAddress.length() < 1)
            throw new IllegalArgumentException(
                          "macAddress cannot be null or blank");

        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);
        }

        DatagramSocket socket = null;
        try {
            InetAddress address = InetAddress.getByName(ip);
            DatagramPacket packet =
                new DatagramPacket(bytes, bytes.length, address, PORT);

            if (logger.isInfoEnabled()) {
                logger.info("Sending datagram (UDP) packet to ip["
                                   + address + "] on port[" + PORT + "]");
                logger.info("Message bytes [" + bytes + "]");
            }

            socket = new DatagramSocket();
            socket.send(packet);
            logger.info("Wake-on-LAN packet sent.");
            return;
        } catch (UnknownHostException e) {
            logger.error(e);
        } catch (SocketException e) {
            logger.error(e);
        } catch (IOException e) {
            logger.error(e);
        } finally {
            if (socket != null && !socket.isClosed()) {
                socket.close();
            }
        }
    }

    private static byte[] getMacBytes(String macStr)
                                     throws IllegalArgumentException {
        byte[] bytes = new byte[6];
        String[] hex = macStr.split("(\\:|\\-)");
        if (hex.length != 6) {
            throw new IllegalArgumentException("Invalid MAC address.");
        }
        try {
            for (int i = 0; i < 6; i++) {
                bytes[i] = (byte) Integer.parseInt(hex[i], 16);
            }
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException(
                                "Invalid hex digit in MAC address.");
        }
        return bytes;
    }

}

written by admin \\ tags: , ,

Sep 09

I switched on my pc and then between 5 and 30 seconds later, before it booted into windows, it would shut down again. It would do this continuously. I disconnected everything from my pc (hard disks, usb devices, all but 1 memory module etc) so I had the bare minimum running. It still happened. So I narrowed it down to cpu, motherboard or power supply.

Doing a search revealed others with similar problems and the most common problem was power supply failures.

I decided to buy a new power supply and the motherboard and cpu upgrade anyway (mine was 3 yrs old). Swapped cpu and motherboard first and the problem was still there. So definitely the power supply. I swapped that, and the problem was resolved.

I then put the old motherboard and power supply on the bench and ran the system from there. I had the power supply fan side down (yes this is bad) – and noticed the system shut down a lot quicker. So I had deduced that it could just be an air flow problem with the power supply overheating. I opened up the power supply (they recommend you not to do this, so be careful!) and there was a lot of dust in there. I vacuumed it all out, ran the system again and the problem hasn’t returned!

So, after all that work (and £250 later) it was dust causing the problem. However, that’s 3 years of dust. I sent back the new power supply and now have put the old one back in and my system has been fine for weeks.

written by admin \\ tags: , , ,

Sep 09

Cisco don’t support a 64 bit client apart from their AnyConnect client, which doesn’t support IPSec. This is a little annoying for those of us who want to run XP, Vista or Windows 7 in 64 bit.

I’ve just installed Windows 7 64 bit and I’ve found a vpn client that is compatible with Cisco! Shrew Soft Inc

I installed version 2.1.5-rc-3 and it works perfectly with Windows 7 and also supports importing Cisco .pcf files.

written by admin \\ tags: , , ,