位置:学校首页 > 学校动态>大连的Python人工智能编程好的
学习Python就来大连达内教育,凭借雄厚的技术研发实力、过硬的教学质量、成熟的就业服务团队,为学员提供强大的职业竞争力,在用人企业中树立了良好的口碑.为不影响您的学习,来校区前请先电话或QQ咨询,方便我校安排相关课程的专业老师为您解答~接下来达内教育的小编为您分享,Python实现用手机监控远程控制电脑
我们可以根据自己的需求编写一些其它功能。下面是完整的代码:
import os
import time
import yagmail
from imbox import Imbox
from PIL import ImageGrab
def send_mail(sender,to,contents):
smtp=yagmail.SMTP(user=sender,host='smtp.163.com')
smtp.send(to,subject='Remote Control',contents=contents)
def read_mail(username,password):
with Imbox('imap.163.com',username,password,ssl=True)as box:
all_msg=box.messages(unread=True)
for uid,message in all_msg:
#如果是手机端发来的远程控制邮件
if message.subject=='Remote Control':
#标记为已读
box.mark_seen(uid)
return message.body['plain'][0]
def shutdown():
os.system('shutdown-s-t 0')
def grab(sender,to):
surface=ImageGrab.grab()
surface.save('surface.jpg')
send_mail(sender,to,['surface.jpg'])
def main():
username='sockwz 163.com'
password='你的授权码'
receiver='2930777518 qq.com'
time_space=5
yagmail.register(username,password)
while True:
#读取未读邮件
msg=read_mail(username,password)
if msg:
if msg=='shutdown':
shutdown()
elif msg=='grab':
grab(username,receiver)
time.sleep(time_space)
if __name__=='__main__':
main()