-
Notifications
You must be signed in to change notification settings - Fork 1
[codex] Validate IP targets and ranges #219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
techmore
merged 1 commit into
codex/python-main-baseline
from
codex/validate-target-ips
Jun 19, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import pytest | ||
|
|
||
| from nmapui.validation import validate_target | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "target", | ||
| [ | ||
| "192.168.1.1", | ||
| "192.168.1.0/24", | ||
| "192.168.1.1-254", | ||
| "10-12.0.0.1-20", | ||
| "scanme.nmap.org", | ||
| "192.168.1.1, 10.0.0.0/8", | ||
| ], | ||
| ) | ||
| def test_validate_target_accepts_supported_target_formats(target): | ||
| assert validate_target(target) == (True, None) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "target", | ||
| [ | ||
| "192.168.1.999", | ||
| "192.168.1", | ||
| "192.168.1.1/33", | ||
| "192.168.1.254-1", | ||
| "192.168.1.1-999", | ||
| ], | ||
| ) | ||
| def test_validate_target_rejects_malformed_ip_like_targets(target): | ||
| valid, error = validate_target(target) | ||
|
|
||
| assert valid is False | ||
| assert error == f"Invalid target: {target}" |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When users enter a Nmap-supported octet-list target such as
192.168.3-5,7.1,validate_targetfirst splits on the comma and then this new numeric fallback rejects the first piece (192.168.3-5) as invalid. I checked the official Nmap target specification, which documents comma-separated numbers/ranges within an octet using that example (https://nmap.org/book/man-target-specification.html); this target previously passed validation and can be scanned by Nmap, so the new malformed-IP guard blocks a valid range form before the scan starts.Useful? React with 👍 / 👎.