Python3.4 Remote control computer (switching machine)

Source: Internet
Author: User

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)

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.