Python3.4 遠程操控電腦(開關機)

來源:互聯網
上載者:User

標籤:python   email   簡訊   開關機   

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 = decode_header(mm['subject'])    if sub[0][1]:        submsg = sub[0][0].decode(sub[0][1])    else:        submsg = sub[0][0]    if submsg.strip() == '關機':        return 0    elif submsg.strip() == '重啟':        return 1    p.quit()def send_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__':    while True:        time.sleep(20)        if check_email() == 0:            send_email()            os.system('shutdown -s -t 1')    #關機            break        if check_email() == 1:            send_email()            os.system('shutdown -r')      #重啟            break
測試成功

其它命令自行添加,這裡只作 關機和重啟. 腦洞大開!

Python3.4 遠程操控電腦(開關機)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.