troglobit / netcalc

Simplified clone of sipcalc with ipcalc looks
BSD 3-Clause "New" or "Revised" License
67 stars 12 forks source link

Add -R Min:Max "Range" option #6

Closed abelbeck closed 7 years ago

abelbeck commented 7 years ago

Feature Request:

When configuring dnsmasq with a range of DHCP addresses (Min:Max) the calculation is quite simple when limiting your scope to only /24 networks. Currently we use some obfuscated bash code to generate the sequential decimal range Min:Max for an arbitrary network. A much better solution would be to use netcalc.

IPv4 options:
  -R Min:Max  Offset IPv4 network Range from Min to Max

Calculation:

RangeMin = (HostMin - 1) + Min

RangeMax = (HostMin - 1) + Max

Conditions: Min > 0 && Min < Max && Max < Hosts/Net

Examples:

netcalc -R 100:200 10.10.10.1/24
...
HostMin  : 10.10.10.1           00001010.00001010.00001010. 00000001
HostMax  : 10.10.10.254         00001010.00001010.00001010. 11111110
...

[Range 100:200]
RangeMin : 10.10.10.100
RangeMax : 10.10.10.200

netcalc -R 10:50 10.10.10.64/26
---
HostMin  : 10.10.10.65          00001010.00001010.00001010.01 000001
HostMax  : 10.10.10.126         00001010.00001010.00001010.01 111110
...

[Range 10:50]
RangeMin : 10.10.10.74
RangeMax : 10.10.10.114

netcalc -R 10:2000 10.20.0.0/16
---
HostMin  : 10.20.0.1            00001010.00010100. 00000000.00000001
HostMax  : 10.20.255.254        00001010.00010100. 11111111.11111110
...

[Range 10:2000]
RangeMin : 10.20.0.10
RangeMax : 10.20.7.208
troglobit commented 7 years ago

Looks like a good feature to have. If I get some time and motivation I can look into it, but it'd be better if someone else step up ... :smiley:

abelbeck commented 7 years ago

I have this working, I should have a PR for you to review Monday.

troglobit commented 7 years ago

Awesome, looking forward to it! How about making the release then, err ... I mean, after merging your PR?

abelbeck commented 7 years ago

Sounds perfect, I'm still testing, tweaking error messages, etc. .

BTW, when testing and using the autogen.sh script I remove the autoreconf 's' option to not create symlinks. Is this something travis wants ? For a release tarball you don't want symlinks.

troglobit commented 7 years ago

The symlinks is not an issue for release tarballs. The "make release" target (and autoconf/automake) takes care of this. There are two use-cases: 1) developer checks out and works with GIT, uses autogen.sh to get configure script that suits his/her system, 2) developer/user downloads tarball and the unpacked version is always self-sufficient.

The GNU people thought about this, unsurprisingly :smirk:

Edit: check previous tarball releases if your'e curious :)

troglobit commented 7 years ago

Thank you so much for all these contributions, @abelbeck! I've updated the man page and ChangeLog, starting the release procedure now, hopefully done later tonight (CET), at the latest tomorrow.

abelbeck commented 7 years ago

@troglobit It was truly a pleasure working with you.