added IP validation with IPv6 and CIDR range support #15
+28
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🧩 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.
⚠️ Iability to handle IP ranges using CIDR notation.
🚫 No IPv6 support, limiting modern compatibility.
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.