Mobile phone magic wand: Remote Computer Shutdown

Source: Internet
Author: User

In this article, the mobile phone uses a computer to access the Internet and needs to be remotely shut down during sleep (too cold, too lazy to get up ^_^ ).

I mentioned how Android phones use computers to access the Internet (http://www.cnblogs.com/MikeZhang/archive/2012/02/04/androidComputerWifi.html ),
This articleArticleIt will be followed by an introduction to how to remotely shut down (taking windows as an example to provide an idea ).

Imagine this scenario: using an Android phone in the bed in winter, surfing the Internet through a computer (watching videos ......), Get up and shut down your computer while you are sleeping ...... It's not good!
So we need a remote shutdown software, but we can't trust it from a third party. What should we do?
Write it yourself!
In fact, it is very simple. The principle is as follows:
WINDOWS shutdown command: "shutdown-s-t 0 ",ProgramThe principle is to trigger this call through socket.
Here is a python example.Code, You can rewrite it.

PC server code:

 1   '''  
2 File: shutdownsvr. py
3 Author: Mike
4 E-mail: Mike_Zhang@live.com
5 '''
6 Import Socket, OS
7 Sock = socket. socket (socket. af_inet, socket. sock_stream)
8 Sock. BIND (( ' 192.168.123.1 ' , 12345 )) # My IP
9 Sock. Listen (5)
10 While True:
11 Connection, address = sock. Accept ()
12 Try :
13 Connection. setTimeout (5)
14 Buf = connection. Recv (1024)
15 If Buf = ' Shutdown ' :
16 OS. System ( ' Shutdown-s-t 0 ' )
17 Except Socket. Timeout:
18 Print ' Time out '
19 Connection. Close ()
20

Android client code:

 1   '''  
2 File: shutdowncli. py
3 Author: Mike
4 E-mail: Mike_Zhang@live.com
5 '''
6 Import Socket
7 Sock = socket. socket (socket. af_inet, socket. sock_stream)
8 Sock. Connect (( ' 192.168.123.1 ' , 12345 ))
9 Sock. Send ( ' Shutdown ' )
10 Sock. Close ()

Tip: Python needs to be installed on Android
Okay, that's all. I hope it will help you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.