Friday, February 1, 2013

Shut down windows from web and mobile

Hello Readers,

It's been a while since I posted on the blog and this post is little off-topic. Anyway, today my friend put forth this idea. What if we can shut down our machines remotely. I said it is possible and infact many people are using it to remotely shut down their servers. I couldn't resist the temptation to come home and try it out myself. Through this post I will share with you how we can do it.

The basic idea is very simple. Your computer runs a web server on which a php page having the shutdown code is stored. A remote host or mobile simply accesses this page which runs the code and system command is executed.

For this technique, you will need wamp or xampp server hosted on your computer and a mobile or pc preferably on the same network. I wont go into details of installing servers. For this tutorial, I am using wamp server and mobile both on the same wifi network.

First of all, create a simple PHP file-
<?php
$output = shell_exec('shutdown /s /t 00');
echo " $output ";
?>
Give it any name  (say shutdown.php) and store it under root directory of your web server.

Then start the web server. Make sure that the firewall is turned off. Note down the ip address of this computer by going into cmd and typing "ipconfig".

In my case, it is 192.168.0.100.
Check if your web server is running properly by opening http://localhost/ from the address bar of your web browser.

Now all you have to do is access this php file from any other location on the network. You can access it through mobile or any computer by typing
http://192.168.0.100/shutdown.php
replace the ip with your internal network ip address.

And once you hit enter, your mobile will request the shutdown.php page which will be received by the server installed on the pc. It will then execute the php code inside the page which contains nothing but a system command "shutdown" that starts the process of shutdown. Hence the windows will shut down!

Same concept can be extended to linux platform by simply replacing the shutdown command by its equivalent in linux. Also make sure that the server process running this code has enough privileges to execute the command.

The php program I used is very simple just for the sake of demonstration. In real life, you should not allow the remote user to execute system commands unless he/she is authenticated to the system.
With port forwarding on your router enabled, you can also shut down your PC from anywhere, but again, that is risky from security point of view.

Thanks!
Feel free to ask your doubts in the comments below :)

2 comments:

  1. This blog is definitely rather handy since I’m at the moment creating an internet floral website – although I am only starting out therefore it’s really fairly small, nothing like this site. Can link to a few of the posts here as they are quite. Thanks much. Zoey Olsen

    ReplyDelete
  2. This blog is definitely rather handy since I’m at the moment creating an internet floral website – although I am only starting out therefore it’s really fairly small, nothing like this site. Can link to a few of the posts here as they are quite. Thanks much. Zoey Olsen

    ReplyDelete