Skip to content

Conversation

@mukeshdhadhariya
Copy link

🧩 Summary

This PR improves the IP blocking system by adding comprehensive validation, IPv6 compatibility, and CIDR (range) handling. These changes ensure that only valid, properly formatted IPs are processed, enhancing system security and stability.

🚀 Changes Made
✅ Added IP address validation using Python’s ipaddress module.
🌐 Added full support for both IPv4 and IPv6 addresses.
📡 Implemented CIDR range handling for blocking/unblocking IP ranges.
🛠 Updated block_ip and unblock_ip methods to validate and process IPs safely.

🧩 Introduced a private helper _is_valid_ip for centralized validation logic.

🧠 Why This Fix Is Needed

Previously, the system lacked IP validation and range support, causing issues such as:

❌ Acceptance of invalid/malformed IP addresses.
🚫 No IPv6 support, limiting modern compatibility.
⚠️ Iability to handle IP ranges using CIDR notation.

These limitations could lead to incorrect firewall behavior, inconsistent logging, and potential security vulnerabilities.

✅ Testing Performed

🧪 Tested valid and invalid IPv4 addresses.
🧪 Tested valid and invalid IPv6 addresses.
🧪 Verified proper CIDR range blocking (e.g., 192.168.1.0/24, 2001:db8::/32).

🧾 Confirmed invalid inputs are gracefully rejected and logged with warnings.

🔒 Security & Stability Improvements
🛡 Prevents accidental or malformed IP blocking.
⚙️ Adds future-proofing for IPv6-based environments.
📈 Improves reliability and consistency across all IP operations.

Refactor IP blocking logic to support IP normalization and whitelisting. Added validation and improved platform-specific blocking commands.
Refactor IPBlocker to improve IP validation and whitelist handling.
@mukeshdhadhariya
Copy link
Author

mukeshdhadhariya commented Nov 9, 2025

@utkarshkgithub review this PR #14

@mukeshdhadhariya
Copy link
Author

@utkarshkgithub can you merge this?

@utkarshkgithub
Copy link
Collaborator

@mukeshdhadhariya , i also need you to implement IPv6 blocking and unblocking using ip6tables

@utkarshkgithub
Copy link
Collaborator

@utkarshkgithub can you merge this?

Your commits message don't follow the guideline , i am afraid you have to either rewrite commit history or pull another pr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants