import smtplib
import pyperclip
import time
import threading
import win32gui
import win32process
import psutil
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
from PIL import ImageGrab
import os
from pynput import keyboard
import socket
import uuid
import platform
import requests
# System details
system_number = input("Enter system number or student ID: ")
# Email Configuration
EMAIL_ADDRESS = "sender mail "
EMAIL_PASSWORD ="sender password"
TO_EMAIL = receiver_email = input("Enter receiver email: ")
# Function to gather system information
def get_system_info():
try:
hostname = socket.gethostname()
local_ip = socket.gethostbyname(hostname)
public_ip = requests.get("https://api64.ipify.org?format=json").json().get("ip", "Unavailable")
mac = ':'.join(['{:02x}'.format((uuid.getnode() >> i) & 0xff) for i in range(0, 8 * 6, 8)][::-1])
system = platform.system()
release = platform.release()
version = platform.version()
architecture = platform.architecture()[0]
processor = platform.processor()
return f"""
System Number/ID: {system_number}
Hostname: {hostname}
Local IP Address: {local_ip}
Public IP Address: {public_ip}
MAC Address: {mac}
Operating System: {system} {release}
OS Version: {version}
Architecture: {architecture}
Processor: {processor}
"""
except Exception as e:
return f"Error retrieving system info: {str(e)}"
# Gather system info once
SYSTEM_INFO = get_system_info()
# Function to send email with screenshot and system info
def send_email(subject, body, screenshot_path=None):
try:
msg = MIMEMultipart()
msg["From"] = EMAIL_ADDRESS
msg["To"] = TO_EMAIL
msg["Subject"] = subject
msg.attach(MIMEText(f"{body}\n\nSystem Details:\n{SYSTEM_INFO}", "plain"))
if screenshot_path:
attachment = open(screenshot_path, "rb")
part = MIMEBase("application", "octet-stream")
part.set_payload(attachment.read())
encoders.encode_base64(part)
part.add_header("Content-Disposition", f"attachment; filename={os.path.basename(screenshot_path)}")
msg.attach(part)
attachment.close()
with smtplib.SMTP("smtp.gmail.com", 587) as server:
server.starttls()
server.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
server.send_message(msg)
print("Alert email sent.")
except Exception as e:
print(f"Failed to send email: {e}")
# Function to take a screenshot
def take_screenshot():
screenshot_path = "screenshot.png"
screenshot = ImageGrab.grab()
screenshot.save(screenshot_path)
return screenshot_path
# Function to monitor clipboard for copy-paste actions
def monitor_clipboard():
last_clipboard = ""
while True:
try:
clipboard_content = pyperclip.paste()
if clipboard_content != last_clipboard:
last_clipboard = clipboard_content
print("Copy-paste detected!")
screenshot_path = take_screenshot()
send_email("Copy-Paste Alert", f"A copy-paste action was detected. Clipboard text:\n{clipboard_content}", screenshot_path)
os.remove(screenshot_path)
except Exception as e:
print(f"Error monitoring clipboard: {e}")
time.sleep(1)
# Function to detect AI tools like Google Gemini (by process name or window title)
def detect_ai_usage():
ai_tools = ["gemini", "chatgpt", "openai", "bard", "cortex","chrome","ChatGPT"] # Example AI tool names/processes
while True:
try:
# Check active processes for AI tools
for proc in psutil.process_iter(['pid', 'name']):
if any(ai_tool.lower() in proc.info['name'].lower() for ai_tool in ai_tools):
print(f"AI tool detected: {proc.info['name']} with PID {proc.info['pid']}")
screenshot_path = take_screenshot()
send_email("AI Tool Usage Detected", f"An AI tool was detected: {proc.info['name']}.", screenshot_path)
os.remove(screenshot_path)
time.sleep(5) # Check every 5 seconds
except Exception as e:
print(f"Error detecting AI usage: {e}")
time.sleep(30)
# Function to monitor active window
def monitor_active_window():
last_window = ""
while True:
try:
hwnd = win32gui.GetForegroundWindow()
_, pid = win32process.GetWindowThreadProcessId(hwnd)
process = psutil.Process(pid)
window_title = process.name()
if window_title != last_window:
last_window = window_title
print(f"Window change detected: {window_title}")
screenshot_path = take_screenshot()
send_email("Tab Change Alert", f"A tab/window change was detected: {window_title}", screenshot_path)
os.remove(screenshot_path)
except Exception as e:
print(f"Error monitoring active window: {e}")
time.sleep(1)
# Function to detect suspicious typing patterns
def on_key_press(key):
try:
if key == keyboard.Key.tab:
print("Tab detected during typing!")
screenshot_path = take_screenshot()
send_email("Suspicious Typing Alert", "A suspicious key (Tab) was pressed during typing.", screenshot_path)
os.remove(screenshot_path)
except Exception as e:
print(f"Error in key monitoring: {e}")
# Main function to run monitoring tasks
def main():
# Start clipboard monitoring in a separate thread
clipboard_thread = threading.Thread(target=monitor_clipboard, daemon=True)
clipboard_thread.start()
# Start AI detection in a separate thread
ai_detection_thread = threading.Thread(target=detect_ai_usage, daemon=True)
ai_detection_thread.start()
# Start active window monitoring in a separate thread
window_thread = threading.Thread(target=monitor_active_window, daemon=True)
window_thread.start()
# Start key monitoring
with keyboard.Listener(on_press=on_key_press) as listener:
listener.join()
if __name__ == "__main__":
main()