Python3.4 Remote Control of Computer on/off and python3.4 remote control

Source: Internet
Author: User

Python3.4 Remote Control of Computer on/off and python3.4 remote control

The example in this article shares with you the code for remotely controlling computers using Python for your reference. The details are as follows:

Import poplib import sys import smtplib from email. mime. text import MIMEText import OS from email. header import decode_header import email import time def check_email (): try: p = poplib. POP3 ('pop .163.com ') p. user ('***** @ 163.com') p. pass _ ('********') ret = p. stat () failed T: print ('login failed! ') Sys. exit (1) str = p. top (ret [0], 0) strlist = [] for x in str [1]: try: strlist. append (x. decode () failed T: try: strlist. append (x. decode ('gbk') returns T: strlist. append (x. decode ('big5') mm = email. message_from_string ('\ n '. join (strlist) sub = decode_header (mm ['subobject']) 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. str Ip () = 'restart': return 1 p. quit () def send_email (): user = '******** @ qq.com' pwd = '************' to = ['****** @ 163.com ', * @ 139.com '] # a text message will be sent to the email to show you whether the message is successful. msg = MIMEText ('') msg ['subobject'] = 'COMMAND received! '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 (20) if check_email () = 0: send_email () OS. system ('shutdown-s-t 1') # shutdown break if check_email () = 1: send_email () OS. system ('shutdown-R') # restart break

Test successful

Add other commands by yourself. Here, only shutdown and restart. The brain hole is wide open!

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.