通过邮箱远程控制电脑

转自本人在知乎上面的答案印如意Fitz

通过往邮箱发送邮件,从而达到控制电脑or开始抓取数据or播放音乐等系列操作。

like that:

先用我的常用邮箱给我备胎邮箱发送一封主题为“shutdown”的邮件

然后我要关机的电脑检测到了自动关机并发挥一封主题为“already shutdown”的邮件

原理:我要关机的电脑脚本不断检测我的备胎邮箱是否有“shutdown”主题的来自我常用邮箱的邮件,如果有则返回一封“已经关机”的邮件给我常用邮箱,并且自己给自己发一封主题为haha的邮箱,从而避免下次一打开脚本就关机。(时间神马的都可以自己设定,我设定的比较短)

#coding:utf-8
#python 3.4
#author yinruyi
#email  yinruyi.hm@gmail.com
import poplib,email
from email.header import decode_header
import smtplib
import time
import os,sys
 
def accp_mail():
        host = "pop3.sina.com"
        username = "yinruyi233@sina.com"#关机邮箱
        password = "233333333"#邮箱密码
        pp = poplib.POP3(host)
        pp.set_debuglevel(1)
        pp.user(username)
        pp.pass_(password)
        ret = pp.stat()
        ret = pp.list()
        down = pp.retr(len(ret[1]))
        a=down[1][10].decode('utf-8')
        b=down[1][33].decode('utf-8')
        if a!="X-Sender: ruyi.yin@qq.com":#我常用的邮箱
                pass
        else:
                if b=="Subject: shutdown":#发送关机主题
                #depend on the down itself
                        return 0
        pp.quit()
def send_mail():
        handle = smtplib.SMTP('smtp.sina.com', 25)
        handle.login('yinruyi233@sina.com','233333333')#关机邮箱帐号和密码
        msg = "To: yinruyi233@sina.com\r\nFrom: yinruyi233@sina.com\r\nSubject: haha \r\n\r\nstart\r\n"
        #从关机邮箱到关机邮箱主题为haha的邮件
        handle.sendmail('yinruyi233@sina.com','yinruyi233@sina.com', msg)
        #发送
        handle.close()
def send_mail1():
        handle = smtplib.SMTP('smtp.sina.com', 25)
        handle.login('yinruyi233@sina.com','23333333')#关机邮箱帐号和密码
        msg = "To: ruyi.yin@qq.com\r\nFrom: yinruyi_hm@sina.com\r\nSubject: already shutdown \r\n\r\nstart\r\n"
        #从关机邮箱到常用邮箱主题为已经关机的邮件
        handle.sendmail('yinruyi_hm@sina.com','ruyi.yin@qq.com', msg)
        handle.close()
if __name__=='__main__':
        while 1:
                time.sleep(5)
                if accp_mail()==0:
                        #print('just success')
                        send_mail()
                        #让关机邮箱自己给自己发一封不同于shutdown的邮件
                        send_mail1()
                        #让关机邮箱给自己的常用邮箱发一封已经关机的邮件
                        os.system('shutdown -f -s -t 10 -c closing...')
                        #关机
                        break

 

posted @ 2015-03-26 13:25  Fitz_Yin  阅读(1699)  评论(0编辑  收藏  举报