Joke Collection Website - Blessing messages - How python realizes remote control of computer (combined with WeChat)

How python realizes remote control of computer (combined with WeChat)

I don't know if you have the trouble that your computer is always used by others and you are too embarrassed to set a password, so I designed a program with python to realize free control.

Although the function is simple, you can realize more functions through its ideas.

The general function is mainly two parts,

First, as soon as the computer is turned on, my mobile phone can be notified.

Second, you can control the computer to shut down by sending a specific email through your mobile phone.

Step 1: Apply for an email address, bind this email address to your mobile phone number, and then you set up a message notification in this email address if there is any new email, so that when you turn on the phone, send an email to this email address, and my mobile phone will receive a message notification.

Step 2: Through python script, regularly check whether there is any specified mail in the mailbox of 163.com, and if there is, perform a specific function (mine is to shut down).

After the first step is successful. The mobile phone can also send an email through the number 10658 139, and edit the short message format, such as: test @163.com (space) subject (space) body.

In this way, if I want to turn off my computer, I will send an email with the theme' Turn off' to 163 mailbox, and the program will perform the shutdown action after detecting this email.

Note: the format of mobile phone email, pay attention to the output of get_payload when reading email, and match the content of your email according to the output, which I encountered at that time.

problem

When I got back, I thought about it. Since it can be controlled by mobile email, everyone uses smart phones, and everyone likes to play WeChat. Then there is an email assistant in WeChat to remind you of new emails in real time, which makes it easier for you to control your machine! ! ! ! !

#! /etc/bin/env python

#-*-Code =utf-8-*-

#auth@: Deng Yongqiang

# blog @:blog . Sina . com . cn/kaiyongdeng

Import pop-up menu, email

Import decode_header from email.header

Import smtplib

Import time

Import operating system, system

Random import

Def account mail ():

Try:

P = pop-up B. POP3('pop.qq.com ')

P. user ("user name")

P.pass_ ('password')

ret = p.stat()

Except the pop-up b.error_proto, e:

Return 1

Print "Login Failed:", e

System exit (1)

# For I( 1, ret[0]+ 1) in the range:

# str=s.top(i,0)

# strlist=[]

# for x in str[ 1]:

# Try:

# strlist.append(x.decode())

# Except:

# Try:

# strlist.append(x.decode('gbk '))

# Except:

# strlist.append(x.decode('big5 '))

#

# mm = email.message_from_string('

. join(strlist))

# sub = decode _ header(mm[' subject '])

# if sub[0][ 1]:

# submsg = sub[0][0]。 decode(sub[0][ 1])

# Otherwise:

# submsg = sub[0][0]

#

# if submsg.strip()=='startpc ':

# s.dele (1)

# Returns 0

#

# s. Exit ()

# return 1

#

For item [1] in p.list ():

number,octets = item.split(' ')

# print "message %s: %sbytes"% (number, octet)

lines = p.retr(number)[ 1]

msg = email.message_from_string("

".Connection (line))

# print msg.as_string()

print msg.get_payload()

If msg.get_payload()== "Go.

":

Return 0

Def send mail ():

Try:

handle = smtplib。 SMTP('smtp. 163.com ',25)

Handle.login ('* * * * @163.com',' password')

Msg = "To :********@qq.com.

From: * * * * * @163.com

Theme: startpc

begin

"

handle . sendmail(' * * * * * * * * * @ 163 . com ',' * * * * * * * * * @ QQ . com ',msg)

handle.close()

Return 1

Except:

Return 0

if __name__=='__main__ ':

while send_mail()==0:

Time. Sleep (2)

And 1:

Time. Sleep (5)

if accp_mail()==0:

Operating system ('off -f -s -t 10 -c off ...')

# Print "Hahahahahahahahaha, it worked! ! ! ! ! ! "

break