zoukankan      html  css  js  c++  java
  • python 远程操控电脑

    import itchat
    import os
    import time
    import cv2

    sendMsg = u"{消息助手}:暂时无法回复"
    usageMsg = u"使用方法: 1.运行CMD命令:cmd xxx (xxx为命令) "
    u"-例如关机命令: cmd shutdown -s -t 0 "
    u"2.获取当前电脑用户:cap 3.启用消息助手(默认关闭):ast "
    u"4.关闭消息助手:astc"
    flag = 0 #消息助手开关
    nowTime = time.localtime()
    filename = str(nowTime.tm_mday)+str(nowTime.tm_hour)+str(nowTime.tm_min)+str(nowTime.tm_sec)+".txt"
    myfile = open(filename, 'w')

    @itchat.msg_register('Text')
    def text_reply(msg):
    global flag
    message = msg['Text']
    fromName = msg['FromUserName']
    toName = msg['ToUserName']

    if toName == "filehelper":
    if message == "cap":
    cap = cv2.VideoCapture(0)
    ret, img = cap.read()
    cv2.imwrite("weixinTemp.jpg", img)
    itchat.send('@img@%s'%u'weixinTemp.jpg', 'filehelper')
    cap.release()
    if message[0:3] == "cmd":
    os.system(message.strip(message[0:4]))
    if message == "ast":
    flag = 1
    itchat.send("消息助手已开启", "filehelper")
    if message == "astc":
    flag = 0
    itchat.send("消息助手已关闭", "filehelper")
    elif flag == 1:
    itchat.send(sendMsg, fromName)
    myfile.write(message)
    myfile.write(" ")
    myfile.flush()

    if __name__ == '__main__':
    itchat.auto_login()
    itchat.send(usageMsg, "filehelper")
    itchat.run()


    此次程序使用的环境是 python3.6 + windows10,在运行程序之前请先确保你已经安装好了 opencv-python 和 matplotlib。通过 pip install 即可安装。

    程序主要是通过使用 itchat 库来登录到微信网页端,然后通过 itchat 来发送消息和接收消息。并通过 opencv 来调用电脑的摄像头,把当前使用电脑的用户拍照下来,发送到你的微信上。至于远程关机是通过调用 os 库,发送 cmd 命名即可实现。

    发送消息「cmd shutdown -s -t 0」即可让当前的电脑关闭。

    发送消息「cap」即可调用电脑摄像头拍摄当前用户,然后把图片发送到微信上。

    当然 cmd 命名还可以做更多有趣的事,大家可以自己去网上搜索下。

  • 相关阅读:
    Bootstrap 网页1
    Bootstrap 网页实例
    Bootstrap 警告框
    Bootstrap 表格
    Bootstrap 小功能
    【BZOJ1706】[usaco2007 Nov]relays 奶牛接力跑 矩阵乘法
    【BZOJ3669】[Noi2014]魔法森林 LCT
    【BZOJ2049,2631,3282,1180】LCT模板四连A
    【BZOJ4071】[Apio2015]巴邻旁之桥 Treap
    【BZOJ1009】[HNOI2008]GT考试 next数组+矩阵乘法
  • 原文地址:https://www.cnblogs.com/daxiaren/p/9448256.html
Copyright © 2011-2022 走看看