Import poplibimport sysimport smtplibfrom email.mime.text import mimetextimport osfrom email.header import Decode_ Headerimport emailimport timedef check_email (): Try:p = Poplib. POP3 (' pop.163.com ') p.user (' *****@163.com ') p.pass_ (' ******* ') ret = P.stat () except:print (' Login failed! ') Sys.exit (1) str = p.top (ret[0], 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 (' \ n '. Join (strlist)) Sub = Deco De_header (mm[' subject ')) if sub[0][1]: submsg = Sub[0][0].decode (sub[0][1]) else:submsg = sub[0][0] If Submsg.strip () = = ' Shutdown ': return 0 elif submsg.strip () = = ' reboot ': return 1 p.quit () def send_email () : User = ' ******* @qq. com ' pwd = ' ********** ' to = [' *****@163.com ', ' *****@139.com '] #139邮件会有短信提醒, let me know if the success msg = Mimetext (') msg[' Subject '] = ' received command! ' msg[' from ' = User msg["to"] = ', '. Join (TO) s = smtplib. SMTP (' smtp.qq.com ') s.login (user, PWD) s.sendmail (user, to, msg.as_string ()) S.close () if __name__ = = ' __main__ ': While True:time.sleep () if check_email () = = 0:send_email () Os.system (' Shutdown -s-t 1 ') #关机 break if check_email () = = 1:send_email () os.system (' Shutdown-r ' ) #重新启动 Break
Test success
Other commands are added on their own, and are only shut down and restarted. The brain hole is big open!
Reprint please indicate the author and source: http://blog.csdn.net/u013511642 Wang Xiaotao _
Python3.4 Remote control computer (switching machine)