Python3.4实现远程控制电脑开关机
本文实例为大家分享了Python实现远程操控电脑的具体代码,供大家参考,具体内容如下
importpoplib
importsys
importsmtplib
fromemail.mime.textimportMIMEText
importos
fromemail.headerimportdecode_header
importemail
importtime
defcheck_email():
try:
p=poplib.POP3('pop.163.com')
p.user('*****@163.com')
p.pass_('*******')
ret=p.stat()
except:
print('Loginfailed!')
sys.exit(1)
str=p.top(ret[0],0)
strlist=[]
forxinstr[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=decode_header(mm['subject'])
ifsub[0][1]:
submsg=sub[0][0].decode(sub[0][1])
else:
submsg=sub[0][0]
ifsubmsg.strip()=='关机':
return0
elifsubmsg.strip()=='重启':
return1
p.quit()
defsend_email():
user='*******@qq.com'
pwd='**********'
to=['*****@163.com','*****@139.com']#139邮件会有短信提醒,让我知道是否成功
msg=MIMEText('')
msg['Subject']='已收到命令!'
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__':
whileTrue:
time.sleep(20)
ifcheck_email()==0:
send_email()
os.system('shutdown-s-t1')#关机
break
ifcheck_email()==1:
send_email()
os.system('shutdown-r')#重启
break
测试成功
其它命令自行添加,这里只作关机和重启.脑洞大开!
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。