Apr
19

WOL: Wake-on-LAN Tutorial with Bonus PHP Script

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.

post_screen.jpg

Mysterious Wake on LAN Setting

bios_screen.jpgI 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.

PHP:
  1. <?
  2. # Wake on LAN - (c) HotKey@spr.at, upgraded by Murzik
  3. # Modified by Allan Barizo http://www.hackernotcracker.com
  4. function WakeOnLan($addr, $mac,$socket_number) {
  5.   $addr_byte = explode(':', $mac);
  6.   $hw_addr = '';
  7.   for ($a=0; $a <6; $a++) $hw_addr .= chr(hexdec($addr_byte[$a]));
  8.   $msg = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255);
  9.   for ($a = 1; $a <= 16; $a++) $msg .= $hw_addr;
  10.   // send it to the broadcast address using UDP
  11.   // SQL_BROADCAST option isn't help!!
  12.   $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
  13.   if ($s == false) {
  14.     echo "Error creating socket!\n";
  15.     echo "Error code is '".socket_last_error($s)."' - " . socket_strerror(socket_last_error($s));
  16.     return FALSE;
  17.     }
  18.   else {
  19.     // setting a broadcast option to socket:
  20.     $opt_ret = socket_set_option($s, 1, 6, TRUE);
  21.     if($opt_ret <0) {
  22.       echo "setsockopt() failed, error: " . strerror($opt_ret) . "\n";
  23.       return FALSE;
  24.       }
  25.     if(socket_sendto($s, $msg, strlen($msg), 0, $addr, $socket_number)) {
  26.       echo "Magic Packet sent successfully!";
  27.       socket_close($s);
  28.       return TRUE;
  29.       }
  30.     else {
  31.       echo "Magic packet failed!";
  32.       return FALSE;
  33.       }
  34.    
  35.     }
  36.   }
  37. // Port number where the computer is listening. Usually, any number between 1-50000 will do. Normally people choose 7 or 9.
  38. $socket_number = "7";
  39. // MAC Address of the listening computer's network device
  40. $mac_addy = "00:12:4G:SF:12:13";
  41. // IP address of the listening computer. Input the domain name if you are using a hostname (like when under Dynamic DNS/IP)
  42. $ip_addy = gethostbyname("myhomeserver.dynamicdns.org");
  43.  
  44. WakeOnLan($ip_addy, $mac_addy,$socket_number)
  45.  
  46.  
  47. ?>

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!

Update: Welcome to all of the digg.com users! Thanks for digging and for coming to my site.

If you enjoyed this post, make sure you subscribe to hacker not cracker via RSS feed or email update!



Additional Reading

Comment View Comments from Other Readers

Popular Posts

Featured Posts

Related Posts

Recent Posts

What's Your Reaction?


Subscribe to this Blog:

Reader Reactions Elsewhere


 

One Response to “Macro-based HTML Tag Support for Microsoft Word”

  1. Vaibhav Says:

    I found this post since it links to mine. I used to use Word 2007 a lot for posting to my blog. But that was till I discovered LiveWriter. You may be interested in this: http://blog.gadodia.net/using-windows-livewriter-to-publish-blog-posts/

    Also, I used to have a problem with it till I realized at a much later date that it also has spellcheck: http://blog.gadodia.net/windows-live-writer-spell-check/

    LiveWriter is a great replacement for Word 2007. Also, if you don't like either of these, just use FireFox or Chrome to type your posts directly into WordPress because both of them provide spell check right in the browser.

    Cheers and thanks for linking to my post.

Leave a Reply

This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)

You must read and type the 4 chars within 0..9 and A..F, and submit the form.

  

Oh no, I cannot read this. Please, generate a

 
Latest Post on Loading...: Please Wait...
admin admin
© 2006 and web design of Allan Ray Barizo from [art] [⁄app].
This site is best viewed with FF and at least 1024x768 resolution.