Click here to Skip to main content
15,881,172 members
Articles / Desktop Programming / Swing

Turn On Your PC/Computer Programmatically / Automatically –Wake On LAN ( WOL ) Over Internet- Wake On WAN ( WOW)

Rate me:
Please Sign up or sign in to vote.
4.71/5 (15 votes)
10 Aug 2009CPOL7 min read 109.9K   4.2K   70   13
Start your Computer by C , C++ , JAVA , .NET ..

Introduction

Everyone of us turns off the machine many times in a day. We do it by a single mouse click on “Turnoff/Shutdown” button in any OS or using 'Shutdown' command typing in command prompt or Shell. Restarting of PC follows the same procedure. Are there any other ways to boot the machine without pressing 'power on' button in CPU manually when PC is in Shutdown state?
Network administrator can shutdown or restart all machines in a network by a single mouse click. Can he start all machines in LAN by a single mouse click when PCs are in shutdown state?
Yes, it can easily be done if your PC is connected to a network, be it in LAN (Local Area Network) or WAN (Wide Area Network).

So at the end of the day, when you leave office/college by thinking my PC is shutdown, network admin cannot scan your PC. But, administrator sitting at his desktop can boot your machine and perform necessary activities using remote desktop.

Surprised!!!!. I know you are thinking that when the computer is in shutdown state, there is no OS / no program running to do it. So who will do the job for me ????
Hold on!!!!

Prerequisites

This article assumes you have minimum networking knowledge and have full access to your PC/Router. Yes, to do it you require minimum support from Hardware / OS / Router. The good thing is that most of the modern hardware and OS support it.

How? 

When you turn off your PC, all devices go off state but a small networking device known as NIC (Network Interface Card) remains on (depending on your NIC settings) and waiting for receiving messages from other network devices.

A special message called 'Magic Code' once received by it boots the PC using special power circuit called 'WOL connector' present in mother board.
A special utility program from other running PC creates 'Magic Packet' which contains MAC (Media Access Control) of target machine and broadcasts it in the network. All NIC cards present in the whole network receive the 'Magic packet' but only the NIC having same MAC address which is present in magic packet boots the PC.
This is not a new technology but not used widely for lack of security. However, some NICs support the security feature called 'SecureOn' which allows you to set a "Magic Packet password" of 6 bytes.

My PC is Connected to LAN and is in Shutdown State. I Want to Turn It On From a Different Machine

  • Turn off your PC and observe whether your LAN card's light is blinking or not. If yes, your LAN card supports it. Not blinking ... wait! Don't be disappointed. Turn on your PC. Go to LAN Card setting in control Panel and enable "Allow this device to bring the computer on". You may find a different name of this property in different OSs.

    Here is the screen shot taken from Windows OS for Intel Pro VM LAN Card:

    Shutdown PC again and see if it is blinking now. No? Stop reading here. Your NIC does not support it.

  • Open BIOS setup (Pressing F10 / Other key) while booting your PC. Go to "Power Option" and enable "SME wake up" or "Enable WOL" option or related Option. If no such options are there, stop reading here. Your PC does not support it. We are almost done. Still there are some chances to get a negative result because some mother boards do not have inbuilt "WOL connector" which is required to flow current to the main board.

  • Open your OS. Type " ipconfig /all " in the command prompt or shell. Your MAC address/ Physical address will be displayed. Note it. Now shutdown your PC. Go to a different PC in LAN. Run the attached JAVA program (it requires Java Runtime Environment). Provide Broadcast address (255.255.255.255 or check with your network admin) and MAC address. If all things go well, you will find your machine turning on. You need to disable "Bios Password", otherwise you need to enter the password manually. (Scroll below to know a bit more about broadcast address.)

    Below is the MAC address taken from Windows OS: 

Why Are We Using MAC Address? 

When the machine is in shutdown state, there is no IP assigned to PC. - Simple answer.
When we are connected to a network and connect to another PC, we need a unique address to connect.
These are IP address and MAC address. These are unique in a network. When we want to connect to another PC which is in the same LAN, IP address has minimum role. What PC requires to know is the MAC address. But still we connect using IP address in LAN. OK.... It finds out the corresponding MAC address for a given IP from network table called ARP (Address resolution Protocol) table. But in WAN, all connections happen using IP address. OK leave it. It is not within the scope of this article.  

Can I Turn on my PC Over the Internet (From cybercafe / School / College)?  How? 

  • First test whether it is working in LAN. If not, stop reading here. Working? Great!!! Now we have to play with the router. 
  • You need a router. Don't worry. You don't require a corporate router. Modern modem comes with Inbuilt router. Go to router console or router manual. Find out whether it supports "Subnet based Broadcasting". If not, you cannot proceed with router. 
  • Turn your Modem/Router in 'always on' mode. If you don't have static IP, you will get a new IP every time you will switch on your router, not PC. This IP should be globally accessible. Using " ipconfig " command, note your router's IP for the first time.

    The following picture is taken from 'Huawei MT882' data one modem for enabling 'always on' feature:

  • Open any port (Generally 7 or 9) on your router and forward any request coming to this port to your PC. Note: The IP is not exactly your computer's IP which you want to turn on from shutdown state. It is the broadcast address for your IP address. For an example, if your PC's IP is 192.168.1.10, broadcast address will be 192.168.1.255. If you are unable to calculate your broadcast address, use any 'Online Subnet calculator'.Link: Online Subnet Calculator. This part is the most vital part of settings. Router should broadcast "Magic packet" coming to given port to all PC in LAN (derived by sub net mask). Many routers disable "Subnet based broadcast" by default.You need to enable it. Some routers do not support this feature. (Refer to the Router manual.)

  • Shutdown your PC. Not router. 
  • Go to a different network ( WAN ) and run the attached program. Provide MAC address and Router IP and Port No. which you have just opened in your router. The program will send Magic packet to router at given port. Router is configured to broadcast this 'Magic packet' to all PCs in the LAN (derived by subnet mask in your network) based on subnet, not Machine IP address.  If all things go well, you will find your machine turning on. 
  • If you are behind a restricted firewall, you may not be able to connect to your router. You have to use HTTP tunnelling to achieve this. You can read about HTTP tunnelling from my another article. You may need to run the program more than once since the protocol used here is UDP, not designed for guaranteed packet delivery.

My Router Does Not Support "sub net based broadcast" So?

Use an 'always on machine' in your LAN. Configure your router to forward "Magic Packet" to only 'always on machine'. As soon as 'Always on machine' receives the magic packet from the router, it broadcasts it in LAN and the target machine will wake up since magic packet contains MAC address of your PC which is in shutdown state.

Conclusion 

Keeping your NIC card always on takes very little power. So if you want to wake up all your machines by a single mouse click, go ahead. It makes the network administrator's life easy.

History

  • 11th August, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer India
India India
SUN certified

Comments and Discussions

 
Generalscreen shots Pin
Subhajeet Ganguly8-Aug-12 17:52
Subhajeet Ganguly8-Aug-12 17:52 
QuestionIt does not work, help!!! Pin
pocho21012-Dec-11 5:28
pocho21012-Dec-11 5:28 
Generalhi this is confusing. Pin
jeremy jow30-Jan-10 15:23
jeremy jow30-Jan-10 15:23 
Questionany way to do this programatically?? Pin
Cool_Dev30-Nov-09 1:00
Cool_Dev30-Nov-09 1:00 
AnswerRe: any way to do this programatically?? Pin
Asu-H25-Jan-10 0:13
Asu-H25-Jan-10 0:13 
GeneralRe: any way to do this programatically?? Pin
Cool_Dev25-Jan-10 1:13
Cool_Dev25-Jan-10 1:13 
GeneralGet IP address using MAC address Pin
aecordoba1-Oct-09 1:07
aecordoba1-Oct-09 1:07 
GeneralRe: Get IP address using MAC address Pin
Asu-H9-Oct-09 19:46
Asu-H9-Oct-09 19:46 
GeneralThen how to Shutdown Pin
issemak17-Aug-09 3:59
professionalissemak17-Aug-09 3:59 
GeneralRe: Then how to Shutdown Pin
Asu-H17-Aug-09 6:11
Asu-H17-Aug-09 6:11 
GeneralRe: Then how to Shutdown Pin
issemak18-Aug-09 3:06
professionalissemak18-Aug-09 3:06 
GeneralRe: Then how to Shutdown: Java Pin
issemak18-Aug-09 3:09
professionalissemak18-Aug-09 3:09 
GeneralRe: Then how to Shutdown: Java Pin
Asu-H18-Aug-09 16:17
Asu-H18-Aug-09 16:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.