netcalc: a tool for aggregating networks, subtracting, and more

Israel G. Lugo israel.lugo at lugosys.com
Tue Nov 1 22:32:44 UTC 2016


Hello,

In the spirit of Ken's script below, I've started development of a tool
which I called NetCalc:

https://github.com/israel-lugo/netcalc (source code)

https://pypi.python.org/pypi/netcalc (Python package)

Currently, NetCalc allows one to add (aggregate) multiple networks,
subtract a network from a larger network, and mix add/subtract
operations with an arbitrary mathematical expression. It supports both
IPv4 and IPv6, and works very efficiently even with very large networks.
It uses the excellent netaddr library for the core address manipulation.

Example usage:

$ netcalc add 198.18.0.0/24 198.18.1.0/24 10.1/16 10/16
10.0.0.0/15
198.18.0.0/23
$ netcalc sub 192.0.2.0/24 192.0.2.0/28
192.0.2.16/28
192.0.2.32/27
192.0.2.64/26
192.0.2.128/25
$ netcalc expr 2001:db8::/34 - 2001:db8::/38 + 2001:db8:100::/41
2001:db8:100::/41
2001:db8:400::/38
2001:db8:800::/37
2001:db8:1000::/36
2001:db8:2000::/35

More features are planned, this is still just an early release. Right
now, things that I can think of being useful:

  * new command for static information (netmask/bitmask, IP range)
  * new command for WHOIS queries
  * new command for splitting a network into smaller networks by prefix
    length
  * ability to specify network arguments through a file
  * ???

The tool is made in Python, and supports both Python 3 (preferred) and
Python 2.

I'm releasing here with the desire that it will be useful to someone,
and hopefully to get some feedback on useful functionality, behavior and
so on.

Regards,

Israel G. Lugo



On 10/20/2016 07:59 PM, Ken Chase wrote:
> re more general 'network utilities' and scripts:
>
>  http://sizone.org/m/hacks/cidrmath.pl
>
> adds and removes subnets from networks giving list of remaining/aggregated (sub)nets.
>
> I couldnt find an online calculator that does this, most are just for 'translation' 
> from subnet masks<>cidr or cisco inverse masks, etc.
>
> Wrote it years ago cuz I had an itch. The included perl module populates a
> hash entry per ip and I didnt want to write my own, so uses lots of ram+cpu on
> big ops (/8 - /9 for eg). But great for earthly operations like /23 - /27 +
> /28.
>
> Yes I should start my own git repo, but i've been lazy.
>
> No warranties provided.
>
> If anyone has a faster/better one, that'd be handy.
>
> /kc
> --
> Ken Chase - ken at sizone.org Toronto & Guelph Canada




More information about the NANOG mailing list