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
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.
$ netcalc add 198.18.0.0/24 198.18.1.0/24 10.1/16 10/16
$ netcalc sub 192.0.2.0/24 192.0.2.0/28
$ netcalc expr 2001:db8::/34 - 2001:db8::/38 + 2001:db8:100::/41
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
* ability to specify network arguments through a file
The tool is made in Python, and supports both Python 3 (preferred) and
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
Israel G. Lugo
On 10/20/2016 07:59 PM, Ken Chase wrote:
> re more general 'network utilities' and scripts:
> 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 +
> 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.
> Ken Chase - ken at sizone.org Toronto & Guelph Canada
More information about the NANOG