微信/邮箱,远程控制关机

应用场景是这样的:

有人打开你的电脑时,电脑联网后,自动给特定邮箱发一封邮件,然后等待回复,如果在这个小时内收到一封有“shut down ”关键词的邮件,电脑自动关机

程序设计的关键点:

1.获取最新邮件,判断邮件收到日期和是否含有关机关键词2.开机自启动

开机自启动可参考http://lvxinwei.sinaapp.com/1066.html 这篇文章介绍的

收发邮件可参考http://lvxinwei.sinaapp.com/1069.html

下面放源代码:

[python]
import win32serviceutil
import win32service
import win32event
import smtplib
import poplib,email,time,os
class test1(win32serviceutil.ServiceFramework):
_svc_name_ = "test_python"
_svc_display_name_ = "test_python"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.running = True
self.is_sent=0
def SvcStop(self):
self.running = False
def SvcDoRun(self):
while self.running:
time.sleep(1)
if self.is_sent==0:
try:
handle = smtplib.SMTP(‘smtp.163.com’, 25)
handle.login(‘xx@163.com’,’xx_pwd’)
msg = "To:yy@qq.comrnFrom:xx@163.comrnSubject:start pc rnrn —-rn"
handle.sendmail(‘xx@163.com’,’yy@qq.com’, msg)
handle.close()
self.is_sent=1
except Exception,e:
print e
self.is_sent=0
if self.is_sent==1:
try:
p=poplib.POP3(‘pop.qq.com’)
p.user(‘xx’)
p.pass_(‘xx_pwd’)
ret = p.stat()
except poplib.error_proto,e:
print "Login failed:",e
list=p.list()[1]
list.reverse()
number,octets =list[0].split(‘ ‘)
lines=p.retr(number)[1]
has_order=[None,None]
for piece in lines:
if "shut down" in piece:
has_order[0]=1
continue
if time.strftime(‘%a, %d %b %Y %H’,time.localtime(time.time())) in piece:
has_order[1]=1
continue
if has_order[0]==1 and has_order[1]==1:
os.system(‘shutdown -f -s -t 10 -c closing…’)
if __name__==’__main__’:
win32serviceutil.HandleCommandLine(test1)
[/python]

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据