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.