Skip to content

add CIDR to IP range flag#779

Open
dogancanbakir wants to merge 1 commit intomainfrom
feat/cidr-to-range
Open

add CIDR to IP range flag#779
dogancanbakir wants to merge 1 commit intomainfrom
feat/cidr-to-range

Conversation

@dogancanbakir
Copy link
Copy Markdown
Member

@dogancanbakir dogancanbakir commented Apr 2, 2026

closes #623

Adds -range / -r flag to convert CIDR to IP range.

echo "192.168.0.0/16" | mapcidr -r -silent
192.168.0.0-192.168.255.255

Summary by CodeRabbit

  • New Features
    • Added --range / -r CLI option to convert CIDR notation to IP address ranges in firstIP-lastIP format.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

Walkthrough

Added a new CLI option --range / -r to mapcidr that converts CIDR notation to IP range format. When enabled, the tool parses the input as CIDR, computes the first and last IP addresses using mapcidr.AddressRange, and outputs a single range string in firstIP-lastIP format, bypassing other processing logic.

Changes

Cohort / File(s) Summary
CIDR to IP Range Conversion
cmd/mapcidr/main.go
Added --range/-r flag and conditional logic in commonFunc to parse CIDR input, compute address range via mapcidr.AddressRange, and output formatted range string; early return skips existing slice/host-splitting logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

bounces with joy 🐰
A CIDR now transforms to ranges so neat,
From first IP to last—a conversion complete!
With --range flag magic, networks take flight,
No splitting required, just clean formatted sight! 🌐
This bunny approves of features so bright! 🥕✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a CIDR to IP range flag as the primary feature.
Linked Issues check ✅ Passed The PR implements the requested feature from issue #623 exactly as specified: a new flag to convert CIDR notation to IP range format (e.g., 192.168.0.0/16 → 192.168.0.0-192.168.255.255).
Out of Scope Changes check ✅ Passed All changes are scoped to implementing the CIDR to IP range conversion feature; no extraneous modifications are present in the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/cidr-to-range

Comment @coderabbitai help to get the list of available commands and usage tips.

@neo-by-projectdiscovery-dev
Copy link
Copy Markdown

neo-by-projectdiscovery-dev bot commented Apr 2, 2026

Neo - PR Security Review

No security issues found

Comment @pdneo help for available commands. · Open in Neo

@dogancanbakir dogancanbakir self-assigned this Apr 2, 2026
@dogancanbakir dogancanbakir requested a review from Mzack9999 April 2, 2026 11:30
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/mapcidr/main.go`:
- Line 124: The --range flag (options.Range) can be silently ignored because
process() only invokes commonFunc() on certain branches; add a compatibility
guard in validateOptions() to detect when options.Range is true together with
mutually incompatible flags (e.g., --aggregate, --shuffle-ip, --sort, --count)
and return an error (or non-zero exit) so the program fails fast; update
validateOptions() to list the conflicting flags, check their values, and surface
a clear error message referencing --range and the conflicting flag(s) so callers
know to remove the incompatible combination.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 18c8da5f-bc36-4697-9054-416c98527b1f

📥 Commits

Reviewing files that changed from the base of the PR and between 07f4c73 and 7b75f27.

📒 Files selected for processing (1)
  • cmd/mapcidr/main.go

flagSet.BoolVarP(&options.Aggregate, "aggregate", "a", false, "Aggregate IPs/CIDRs into minimum subnet"),
flagSet.BoolVarP(&options.AggregateApprox, "aggregate-approx", "aa", false, "Aggregate sparse IPs/CIDRs into minimum approximated subnet"),
flagSet.BoolVarP(&options.Count, "count", "c", false, "Count number of IPs in given CIDR"),
flagSet.BoolVarP(&options.Range, "range", "r", false, "Convert CIDR to IP range (e.g. 192.168.0.0-192.168.255.255)"),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

--range can be silently ignored with other processing flags.
process() only calls commonFunc() on specific paths; with flags like --aggregate, --shuffle-ip, --sort, --count, etc., --range won’t execute and no error is raised. Please fail fast on incompatible combinations in validateOptions().

Proposed guard in validateOptions()
 func (options *Options) validateOptions() error {
@@
 	if options.ToIP4 && options.ToIP6 {
 		return errors.New("IP4 and IP6 can't be converted together")
 	}
+
+	if options.Range && (options.Aggregate || options.AggregateApprox || options.Shuffle ||
+		options.SortAscending || options.SortDescending || options.Count ||
+		options.Slices > 0 || options.HostCount > 0) {
+		return errors.New("range can't be used with aggregate/aggregate-approx/shuffle/sort/count/sbc/sbh")
+	}
+
 	if options.FilterIP != nil && options.MatchIP != nil {
 		return errors.New("both match and filter mode specified")
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/mapcidr/main.go` at line 124, The --range flag (options.Range) can be
silently ignored because process() only invokes commonFunc() on certain
branches; add a compatibility guard in validateOptions() to detect when
options.Range is true together with mutually incompatible flags (e.g.,
--aggregate, --shuffle-ip, --sort, --count) and return an error (or non-zero
exit) so the program fails fast; update validateOptions() to list the
conflicting flags, check their values, and surface a clear error message
referencing --range and the conflicting flag(s) so callers know to remove the
incompatible combination.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add CIDR to Range as option

2 participants