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.