The File Integrity Monitor is a Python-based utility that helps monitor the integrity of files by calculating their hash values and sending alerts when changes are detected. This project provides a simple and efficient way to ensure the integrity of critical files and detect any unauthorized modifications.
- Python 3.7 or later
- Email account with SMTP access (e.g., Gmail, Outlook)
watchdoglibrary: Installation covered in the next step
- Clone the repository:
git clone https://github.com/akshayjain-1/File-Integrity-Monitoring.git - Navigate to the project directory:
cd file-integrity-monitor - Install the required libraries:
pip install -r requirements.txt
-
Set the
EMAILandEMAIL_PWDenvironment variables with your email account credentials. For example, on Linux or macOS, you can use the following commands:export EMAIL="[email protected]" export EMAIL_PWD="your_password"On Windows, you can set environment variables through the System Properties or using thesetcommand. -
Update the
[email protected]and[email protected]placeholders in thesend_alertfunction with your actual email addresses.
- Import the
calculate_hashfunction:from monitor import calculate_hash - Call the
calculate_hashfunction with the file path as an argument:hash_value = calculate_hash('path/to/file.txt') - The function returns the SHA-256 hash value of the file as a string.
- Import the
send_alertfunction:from monitor import send_alert - Call the
send_alertfunction with the alert message as an argument:send_alert('File integrity alert: file.txt has been modified!') - The function sends an email with the alert message to the configured recipient.
Calculates the SHA-256 hash value of a file.
file_path: The path of the file to calculate the hash of.- Returns: The hash value of the file as a string, or
Noneif the file does not exist or cannot be read.
Sends an alert with the given message.
message: The email body to send.- Sends an email with the alert message to the configured recipient.
FileNotFoundError: The file specified in thecalculate_hashfunction does not exist.OSError: An error occurred while reading the file.smtplib.SMTPException: An error occurred while sending the email.
- Check the file path and ensure it exists.
- Verify the file permissions and ensure the script has read access.
- Check the email account credentials and SMTP server settings.
Contributions are welcome! If you'd like to contribute to the project, please fork the repository, make your changes, and submit a pull request.