首页 > 其他 > 详细

通过发送邮件实现对远程pc的控制

时间:2015-11-16 22:34:35      阅读:282      评论:0      收藏:0      [点我收藏+]
#coding:utf-8
#python 2.7.10
#author conard

import poplib,email
from email.header import decode_header
import smtplib
import time
import os,sys

host = "pop3.163.com"
username = "xxxx@163.com"  #slavemail
password = "xxxx"

def accp_mail():
    flag=1
    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]))
    mn=down[1][14].decode(‘utf-8‘)  #host mail
    ms=down[1][13].decode(‘utf-8‘)   #subject
    if (mn==u‘From: hostmail_name‘) and (ms==u‘Subject: shutdown‘):
        flag = 0
    pp.quit()
    return flag

def upda_mail():

    handle = smtplib.SMTP(‘smtp.163.com‘, 25)
    handle.login(username,password)
    msg = "To: slavemail_name\r\nFrom: slavemail_name\r\nSubject: Waiting \r\n\r\nNULL \r\n"
    handle.sendmail(‘slavemail_name‘,‘slavemail_name‘, msg)
    handle.close()        
        
def resp_mail():

    handle = smtplib.SMTP(‘smtp.163.com‘, 25)
    handle.login(username,password) 
    msg = "To: hostmail_name\r\nFrom: slavemail_name\r\nSubject: Shutdown Completed\r\n\r\nDone\r\n"
    handle.sendmail(‘slavemail_name‘,‘hostmail_name‘, msg)
    handle.close()
        
if __name__==‘__main__‘:
    while 1:
        time.sleep(5)
        if accp_mail()==0:
            upda_mail()   #让slave邮箱给自己发一封主题不同于shutdown的邮件
            resp_mail()  #让slave邮箱给host邮箱发送反馈
            os.system(‘regedit‘) 
            #os.system(‘shutdown -s -t 300 -c closing...‘) #关机,300s内可取消关机命令
            break

将slavemail_name替换为从邮箱名字,如 abc@163.com,hostmail_name替换为主邮箱名字

参考:

http://www.zhihu.com/question/27065450

https://github.com/kingname/MCC

 

通过发送邮件实现对远程pc的控制

原文:http://www.cnblogs.com/conard/p/4970128.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!