Skip to content
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

Range / CIDR conversion utility #37

Closed
coderholic opened this issue May 14, 2021 · 14 comments · Fixed by #45
Closed

Range / CIDR conversion utility #37

coderholic opened this issue May 14, 2021 · 14 comments · Fixed by #45
Milestone

Comments

@coderholic
Copy link
Member

Another utility that it'd be great to add to the cli is the ability to convert from cidr to start,end ranges. We commonly do this internally at IPinfo, and our customers sometimes need to do it with our data exports too.

Eg. input:
1.1.1.0,1.1.1.255,other data

Output:
1.1.1.0/24,other data

And vice versa. Should probably support a different range sepator too (eg. 1.1.1.0-1.1.1.255).

@UmanShahzad
Copy link
Contributor

I think we have almost all the base code needed to do this already so that should be good!

@UmanShahzad UmanShahzad added this to the v2 milestone May 14, 2021
@UmanShahzad
Copy link
Contributor

UmanShahzad commented May 14, 2021

Any idea for the name of a tool like this? This would also be the subcommand.

Some ideas:

  • cidrconvert
  • cidrconv
  • cc

@UmanShahzad
Copy link
Contributor

Or two tools that do each separately:

  • cidr2range
  • range2cidr

@coderholic
Copy link
Member Author

Yeah I like 2 tools named cidr2range and range2cidr

@UmanShahzad
Copy link
Contributor

Great, those names might also be easier to get & discover on distribution repos like homebrew/apt.

@UmanShahzad
Copy link
Contributor

UmanShahzad commented May 21, 2021

@coderholic A question about ranges that don't combine nicely into a single CIDR:

What to do about a range like 1.1.1.0,1.1.1.2 which really requires 2 CIDRs 1.1.1.0/31 and 1.1.1.2/32? (Obviously the other way around is not a problem.)

@UmanShahzad
Copy link
Contributor

Just print both, and if so with a comma delimiter between them? Or skip these cases by default with a flag to force outputting multiple CIDRs if necessary?

@UmanShahzad
Copy link
Contributor

For reference, we had a chat and the answer is if we encounter input like:

1.1.1.0,1.1.1.2,other data

we'd output the 2 CIDR result as:

1.1.1.0/31,other data
1.1.1.2/32,other data

i.e. copying the surrounding data per CIDR.

@UmanShahzad
Copy link
Contributor

This'll be available in the v2 release fairly soon. Just wrapping it up.

@UmanShahzad
Copy link
Contributor

When it's released, if there are any other issues let's make new issues for it.

@yermulnik
Copy link

Are there Hombrew tap issues to track progress on adding cidr2range and range2cidr? I can't see these in https://github.com/ipinfo/homebrew-tap so assumed you've gone with adding them to Homebrew tap at once.

@UmanShahzad
Copy link
Contributor

I'll make PRs for getting these on the official homebrew tap tomorrow my time, yes. No point really adding them to the IPinfo tap at this point since it'll be replaced pretty quickly I reckon, given the good feedback we got from the homebrew guys on the previous stuff.

@UmanShahzad
Copy link
Contributor

Made PRs for Homebrew:

cidr2range: Homebrew/homebrew-core#78164
range2cidr: Homebrew/homebrew-core#78166

@yermulnik
Copy link

Awesome 🥳 Thanks a lot!

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 a pull request may close this issue.

3 participants