I love tweaking my computer! Every opportunity that allows me to specify what I want makes me excited of the possibilities. (With the exception of Azureus. That’s just too confusing for me!) In fact, the first thing I check after installing a new program is the possible existence of "Options," "Preferences," "Tools," "Configuration," "Settings," or "Setup!"
BIOS (or CMOS)
When I first became involved with computers, I started to mess around with the BIOS. It was an intriguing little 16-color control panel. I’m talking about those settings that you can change after pressing "F1," "F2," or "Delete" before the operating system starts to load.
Mysterious Wake on LAN Setting
I pretty much understood all the settings and what each one did except for this strange "Remote Wake-on-LAN." It wasn’t until much later I discovered that initiating this option allows the computer to boot upon command from the network. Personally, that is ultra cool! But at the time, I really didn’t have a use for it. Then came college.
College Needs
I increasingly saw a need to get a laptop. There were countless times when I needed to access my computer while on campus. Sadly, the only computers that I could use were the ones in the computer labs. I came up with a nifty idea that wouldn’t cost a dime. Since I can’t leave my computer on all day, why don’t I use the Wake-on-LAN function to turn it on remotely and then implement a remote access setup. It would enable me to access my computer from anywhere regardless of whether it was off or on!
How it Works
Wake-on-LAN gives me the impression of an undocumented obscure little function that hardly anyone makes use of. Really, it is so simple that the lack of documentation is understandable. Essentially, enabling this function allows the network device to stay half-awake while the rest of the computer is off. It consumes a miniscule amount of electricity while constantly listening to the network. The network device waits until it receives a "magic packet" (seriously!). A magic packet is a small bundle of data consisting of the bytes "FF FF FF FF FF FF" followed by 16 repetitions of the listening network device’s MAC address.
Creating the "Magic Packet"
A magic packet is fairly easy to generate. Depicus provides great freeware tools that allow you to input the parameters. Personally, I PHP programmed my server to generate the packet. I found some useful PHP WOL code from the PHP website. I modified it so that it will fit my liking. Just change the lines in the end.
PLAIN TEXT – CLICK TO REMOVE NUMBERS
PHP:
-
<?
-
# Wake on LAN – (c) HotKey@spr.at, upgraded by Murzik
-
# Modified by Allan Barizo http://www.hackernotcracker.com
-
flush();
-
function WakeOnLan($addr, $mac,$socket_number) {
-
$addr_byte = explode(‘:’, $mac);
-
$hw_addr = ”;
-
for ($a=0; $a <6; $a++) $hw_addr .= chr(hexdec($addr_byte[$a]));
-
$msg = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255);
-
for ($a = 1; $a <= 16; $a++) $msg .= $hw_addr;
-
// send it to the broadcast address using UDP
-
// SQL_BROADCAST option isn’t help!!
-
$s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
-
if ($s == false) {
-
echo "Error creating socket!\n";
-
echo "Error code is ‘".socket_last_error($s)."’ – " . socket_strerror(socket_last_error($s));
-
return FALSE;
-
}
-
else {
-
// setting a broadcast option to socket:
-
$opt_ret = socket_set_option($s, 1, 6, TRUE);
-
if($opt_ret <0) {
-
echo "setsockopt() failed, error: " . strerror($opt_ret) . "\n";
-
return FALSE;
-
}
-
if(socket_sendto($s, $msg, strlen($msg), 0, $addr, $socket_number)) {
-
echo "Magic Packet sent successfully!";
-
socket_close($s);
-
return TRUE;
-
}
-
else {
-
echo "Magic packet failed!";
-
return FALSE;
-
}
-
}
-
}
-
// Port number where the computer is listening. Usually, any number between 1-50000 will do. Normally people choose 7 or 9.
-
$socket_number = "7";
-
// MAC Address of the listening computer’s network device
-
$mac_addy = "00:12:4G:SF:12:13";
-
// IP address of the listening computer. Input the domain name if you are using a hostname (like when under Dynamic DNS/IP)
-
$ip_addy = gethostbyname("myhomeserver.dynamicdns.org");
-
WakeOnLan($ip_addy, $mac_addy,$socket_number)
-
?>
Common Hurdles
There are a couple of common problems computer users come across when trying to implement Wake-on-LAN.
- Physical Network Layer – To my knowledge, WOL will only work with Ethernet. Sorry! No Wi-fi! (Though, I heard that there are some very rare exceptions!)
- Incompatible BIOS or network device – Sometimes the BIOS or the Ethernet Device will not support WOL. These are the two main components of Wake-on-LAN. The Ethernet detects the "magic packet" and the BIOS turns the computer on.
- Network Infrastructure – In order for WOL to work, the "magic packet" must go through a direct, IP-address-specific route. That means if there are any routers or if your computers on the network share a public IP address then you’ll need to do some port mapping when send magic packet via the Internet.
Last Tips
If you’re still having trouble with WOL, try sending the magic packet to the broadcast address of the network that the listening computer is a part of. The broadcast address is the IP address prefix with 255 appended at the end. Mine is 192.168.0.255. (Just a little FYI: Everything that is directed to the broadcast address goes to every computer on the network.) Good luck!
http://www.hackernotcracker.com/2006-04/wol-wake-on-lan-tutorial-with-bonus-php-script.html