added IP validation with IPv6 and CIDR range support#15
Closed
mukeshdhadhariya wants to merge 0 commit intoOPCODE-Open-Spring-Fest:mainfrom
Closed
added IP validation with IPv6 and CIDR range support#15mukeshdhadhariya wants to merge 0 commit intoOPCODE-Open-Spring-Fest:mainfrom
mukeshdhadhariya wants to merge 0 commit intoOPCODE-Open-Spring-Fest:mainfrom
Conversation
Contributor
Author
|
@utkarshkgithub review this PR #14 |
Contributor
Author
|
@utkarshkgithub can you merge this? |
Collaborator
|
@mukeshdhadhariya , i also need you to implement IPv6 blocking and unblocking using ip6tables |
Collaborator
Your commits message don't follow the guideline , i am afraid you have to either rewrite commit history or pull another pr. |
Contributor
Author
|
@utkarshkgithub resolve conflict so review |
Collaborator
1879955 to
982be6a
Compare
982be6a to
78628eb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.