This Python script captures a webcam photo and sends an email alert with approximate location (via IP) on Windows events like PC unlock, lock, or logon. Useful for basic security monitoring.
- Captures photo from webcam.
- Gets approximate location from IP (city, region, etc.).
- Emails photo and details to a receiver.
- Logs events to a file.
- Runs via command line or Task Scheduler.
- Python 3.12+.
- Libraries:
pip install opencv-python requests. - Windows OS (for Task Scheduler integration).
- Gmail account for sending emails (or modify for other providers).
Do not hardcode email credentials! Use environment variables:
- Set
EMAIL_SENDERandEMAIL_PASSWORDin your system environment. - In the script, use
os.environ.get('EMAIL_SENDER')andos.environ.get('EMAIL_PASSWORD').
For Gmail: Enable 2FA and use an "App Password" from Google Account settings.
- Clone this repo:
git clone https://github.com/yourusername/PC-Security-Camera.git. - Edit
security_camera.py:- Update
SAVE_FOLDERif needed (default: C:\SecurityCaptures). - Set
EMAIL_RECEIVERto your email. - Secure credentials as above.
- Update
- Test: Run
python security_camera.py testin command prompt.
- Open Task Scheduler.
- Create Task:
- Trigger: On workstation unlock/lock/log on.
- Action: Start
python.exewith arguments:path\to\security_camera.py unlock(or lock/logon).
- Run with highest privileges.
- Manual:
python security_camera.py unlock(captures photo and sends email). - Events: unlock, lock, logon, test.
- Photos: Saved in
C:\SecurityCaptures. - Logs:
C:\SecurityCaptures\security_log.txtandC:\SecurityScript\task_debug.log.
- No webcam? Script skips photo but sends location.
- Email issues: Check credentials and firewall.
- Location inaccurate? It's IP-based (not GPS).
Contributions welcome! Report issues on GitHub.