#1024660 ITP: ranges -- Command line program to extract ranges from various types of lists, e.g. integer numbers, dates, IP and MAC addresses.

Package:
wnpp
Source:
wnpp
Submitter:
Sandro-Alessio Gierens
Date:
2025-11-29 16:52:04 UTC
Severity:
normal
#1024660#5
Date:
2022-11-22 19:32:11 UTC
From:
To:
* Package name    : ranges
  Version         : 1.0.0
  Upstream Author : Sandro-Alessio Gierens <sandro@gierens.de>
* URL             : https://github.com/gierens/ranges
* License         : GPLv3
  Programming Lang: C
  Description     : Command line program to extract ranges from various types of lists, e.g. integer numbers, dates, IP and MAC addresses.

ranges is a command line program written in C that extracts ranges from
various types of lists. By default it parses signed decimal integer
lists, but given the right argument it can work with unsigned
hexadecimal, octal and binary numbers, dates, IPv4, IPv6 and MAC
addresses. The list input is given over the standard input, so by pipe,
and is assumed to be sorted, but can have duplicates.

Relevance

I work in a data center and recently had the problem that I needed to
find out which IP addresses of a subnet were not yet assigned in
a /etc/hosts file. Because there were already too many addresses to
get a good overview, I began to wonder if there was any command line
tool that would allow me to compile the list of IPs into a list of
IP ranges, so the gaps and their size would be obvious. Unfortunately
I only found stack overflow discussions suggesting writing a script,
and this is what I did to back then too. While this usually doesn't
take more than a couple of minutes, ranges has too advantages:
It already implements a bunch of different list types including
nasty things like dates for example, and therefore would spare
people from replementing such scripts over and over again. Aside
from that it is written in C and therefore fast. According to my
tests it is, depending on the machine, 20 to 40 times faster than
a comparable Python3 script. It can crunch 130 MB of IPv4 addresses
in a second.

Eventhough I just published the initial release I've been working on
this for a couple of weeks now and extensively checked that it is
stable and secure. My test suite consists of 185 tests that verify
the correct functionality of each mode and argument. Each test is
first run without and then with valgrind memcheck, so there should
not be any leaks or other memory errors.

Maintainance

As the upstream author of the software I would also maintain the
package. This would be my first package, but I already have a make
rules to build a deb package and check it with lintian, so I'm
not unprepared :)

#1024660#10
Date:
2022-11-22 19:48:53 UTC
From:
To:
The package name is very generic.  I would pick something more specific.  Also,
I suspect the speed advantage would be less significant if you used SubnetTree
(python3-subnettree), which does all the hard work in C.  Is this really
needed?

Scott K

#1024660#15
Date:
2022-11-22 20:48:00 UTC
From:
To:
Hi Scott,

Any suggestions? Since it's mostly supposed to be used in Bash pipes I
aimed for something short, and since that name doesn't appear to be used
on any unix like system: https://command-not-found.com/ranges I though I
go for it :)
Good to know that such a package exists! From looking at the README I
don't immediately see that one could write such a script with it, but I
suppose it is possible. That would only solve the problem for IPs though.

But the thing with the Python module is exactly my point. Sure, it is
possible to write a Python script when you stumble across a use-case,
and that is what everybody seems to be doing. But I think compiling
lists into ranges is a generic enough problem, that a ready to use CLI
tool makes sense. Nobody should waste their time re-implementing the
same thing again and again.

I mean it is probably also possible to write a Python script version of
most other pipe tools like wc, uniq, ... but it's still massively
helpful to have those tools on hand everywhere you go. Don't get me
wrong I'm not saying my program would be as useful as any of the
coreutils. Compiling lists into ranges is a rarer use-case, but I had to
implement these kinds of scripts often enough to be convinced, that I
will be helpful for more than one person :)

#1024660#20
Date:
2022-11-22 21:34:20 UTC
From:
To:
ups, typo: ... that *it* will be helpful for more than one person :)