服务器之家

服务器之家 > 正文

python远程邮件控制电脑升级版

时间:2021-06-29 00:10     来源/作者:王小涛_同學

由于前边python3.4实现远程控制电脑开关机写的远程操控电脑,使用的pop登陆有使用频率限制,导致非常被动,有时候邮件无法读取,下面改用post网易邮箱的方法,获取邮件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import urllib.request as request
import http.cookiejar as cookiejar
import urllib.parse
import re
import smtplib
from email.mime.text import mimetext
import time
import win32com.client
import win32con
import win32api
import os
cj = cookiejar.lwpcookiejar()
cookiesupport = request.httpcookieprocessor(cj)
opener = request.build_opener(cookiesupport, request.httphandler)
request.install_opener(opener)
speak = win32com.client.dispatch('sapi.spvoice')
def login(username, pwd):
 post_url = 'https://mail.163.com/entry/cgi/ntesdoor?df=mail163_letter&from=web&funcid=loginone&iframe=1&language=-1&passtype=1&product=mail163&net=c&style=-1&race=254_292_276_bj&uid='+ username + "@163.com"
 headers = {
 'host': 'mail.163.com',
 'origin': 'http://mail.163.com',
 'referer': 'http://mail.163.com/',
 'user-agent': 'mozilla/5.0 (windows nt 6.3; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/44.0.2403.39 safari/537.36'
 }
 post_data = {'savelogin':'0',
 'url2': 'http://mail.163.com/errorpage/error163.htm',
 'username': username,
 'password': pwd
 }
 post_data = urllib.parse.urlencode(post_data).encode('gbk')
 req = request.request(post_url, post_data, headers=headers)
 page = request.urlopen(req, timeout=20).read().decode('gb2312')
 sid = re.compile(r'sid=(.+?)&df').findall(page)[0]
 return sid
def check_email():
 mail_url = 'http://mail.163.com/js6/s?sid='+login('******', '******')+'&func=mbox:listmessages&leftnavrecievemailclick=1&error=no%20conext.module&mbox_folder_enter=1'
 mail_data = {
 'var': '<?xml version="1.0"?><object><array name="items"><object><string name="func">mbox:getallfolders</string><object name="var"><boolean name="stats">true</boolean><boolean name="threads">false</boolean></object></object><object><string name="func">mbox:getfolderstats</string><object name="var"><array name="ids"><string>1,3,18</string></array><boolean name="messages">true</boolean><boolean name="threads">false</boolean></object></object><object><string name="func">mbox:listtags</string><object name="var"><boolean name="stats">true</boolean><boolean name="threads">false</boolean></object></object><object><string name="func">mbox:statmessages</string><object name="var"><array name="fids"><int>1</int><int>2</int><int>3</int><int>4</int><int>18</int><int>5</int></array><object name="filter"><string name="defer">19700101:</string></object></object></object><object><string name="func">mbox:statmessages</string><object name="var"><array name="fids"><int>1</int><int>2</int><int>3</int><int>4</int><int>18</int><int>5</int></array><object name="filter"><string name="defer">:20150617</string></object></object></object></array></object>'
 }
 mail_data = urllib.parse.urlencode(mail_data).encode('utf-8')
 req = request.request(mail_url, mail_data)
 page = request.urlopen(req, timeout=20).read().decode('utf-8', 'ignore')
 subject = re.compile(r'<string name="subject">(.+?)</string>').findall(page)
 return (subject[len(subject)-1])
def send_email():
 user = '******@163.com'
 pwd = '*******'
 to = ['*****@163.com', '*****@139.com']
 msg = mimetext('')
 msg['subject'] = 'ok'
 msg['from'] = user
 msg['to'] = ','.join(to)
 s = smtplib.smtp('smtp.163.com')
 s.login(user, pwd)
 s.sendmail(user, to, msg.as_string())
 s.close()
if __name__ == '__main__':
 while true:
 try:
  cmd = check_email()
  command1 = {'关机': 'shutdown -s -t 1',
   '重启': 'shutdown -r',
   '关闭浏览器': 'taskkill /f /im chrome.exe',
   '关闭qq': 'taskkill /f /im qq.exe',
   '关闭qq': 'taskkill /f /im qq.exe',
   '关闭wifi': 'taskkill /f /im kwifi.exe',
   '关闭音乐': 'taskkill /f /im cloudmusic.exe',
   '打开音乐': 'd:\\网易云音乐\\cloudmusic\\cloudmusic.exe',
   '打开摄像头': 'd:\\python源码\\摄像头监控.py',
   '打开监控': 'd:\\python源码\\winspyon.py',
   '打开qq': 'd:\\腾讯qq\\bin\\qq.exe',
   '打开qq': 'd:\\腾讯qq\\bin\\qq.exe',
   '打开wifi': 'd:\\chrome\\kwifi\\kwifi.exe',
   '打开ss': 'd:\\代理服务器\\shadowsocks-win-dotnet4.0-2.3\\shadowsocks.exe'
   }
  if cmd in command1.keys():
  speak.speak('计算机即将' + cmd)
  send_email()
  if cmd.find('打开') == 0:
   win32api.shellexecute(0, 'open', command1[cmd], '', '', 1)
   if cmd == '打开音乐':
   time.sleep(35)
   win32api.keybd_event(17, 0, 0, 0)
   win32api.keybd_event(18, 0, 0, 0)
   win32api.keybd_event(32, 0, 0, 0)
   win32api.keybd_event(32, 0, win32con.keyeventf_keyup, 0)
   win32api.keybd_event(18, 0, win32con.keyeventf_keyup, 0)
   win32api.keybd_event(17, 0, win32con.keyeventf_keyup, 0)
  else:
   os.system(command1[cmd])
  speak.speak('计算机已经' + cmd + ',任务执行完毕!')
  time.sleep(60)
 except:
  time.sleep(120)

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/u013511642/article/details/46540207

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
2021德云社封箱演出完整版 2021年德云社封箱演出在线看
2021德云社封箱演出完整版 2021年德云社封箱演出在线看 2021-03-15
返回顶部