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

#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

 

转载于:https://www.cnblogs.com/conard/p/4970128.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值