{"id":17922493,"url":"https://github.com/gierens/ranges","last_synced_at":"2025-07-28T10:35:12.370Z","repository":{"id":140300918,"uuid":"555072687","full_name":"gierens/ranges","owner":"gierens","description":"Command line program to extract ranges from various types of lists, e.g. integer numbers, dates, IP and MAC addresses.","archived":false,"fork":false,"pushed_at":"2022-11-22T18:39:15.000Z","size":2895,"stargazers_count":5,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T06:48:02.717Z","etag":null,"topics":["c","cli","date","integer","ipv4","ipv6","list","mac-address","pipe","range"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gierens.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-20T22:46:34.000Z","updated_at":"2024-04-03T16:53:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"f5517cda-f1be-4056-b71c-0cce7659dade","html_url":"https://github.com/gierens/ranges","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gierens%2Franges","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gierens%2Franges/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gierens%2Franges/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gierens%2Franges/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gierens","download_url":"https://codeload.github.com/gierens/ranges/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245198721,"owners_count":20576426,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","cli","date","integer","ipv4","ipv6","list","mac-address","pipe","range"],"created_at":"2024-10-28T20:39:25.055Z","updated_at":"2025-03-24T02:32:34.143Z","avatar_url":"https://github.com/gierens.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ranges\n\n![build](https://github.com/gierens/ranges/actions/workflows/build.yml/badge.svg)\n![tests](https://github.com/gierens/ranges/actions/workflows/test.yml/badge.svg)\n![docs](https://github.com/gierens/ranges/actions/workflows/docs.yml/badge.svg)\n\n**ranges** is a command line program written in C that extracts ranges from\nvarious types of lists. By default it parses signed decimal integer lists,\nbut given the right argument it can work with unsigned hexadecimal, octal\nand binary numbers, dates, IPv4, IPv6 and MAC addresses. The list input\nis given over the standard input, so by pipe, and is assumed to be sorted,\nbut can have duplicates.\n\n![ranges demo](docs/ranges.gif)\n\n## Installation\n\nNote that you need `make`, `gcc-11` and `pandoc` to install **ranges** from sources:\n\n### On Linux\nYou can install **ranges** with:\n```bash\nmake\nsudo make install\n```\nYou can uninstall it with:\n```bash\nsudo make uninstall\n```\n\n### On Debian\nOn a Debian-based distro you can also install ranges via a `deb` package with:\n```bash\nmake deb-install\n```\nIn this case removal is done with:\n```bash\nmake deb-uninstall\n```\nNote that I plan to package this for Debian and possibly other distros soon,\nthen installation should become even easier.\n\n## Usage\n\n### SYNOPSIS\n`ranges [-H|-o|-b|-d|-i|-I|-m] [-f] [-h] [FILE]`\n\n### OPTIONS\n\n#### Range Type Options\nWhen no other range type is given, the program will extract ranges form a\nlist of signed decimal numbers in the format DDD...D with D being a decimal\ndigit. An example number would be 1234.\n\n| Option | Description                                                    |\n| ------ |:--------------------------------------------------------------:|\n| **-H**, **\\--hex** | For unsigned hexadecimal numbers e.g. `0x12ab`. |\n| **-o**, **\\--octal** | For unsigned octal numbers e.g. `0o0127`. |\n| **-b**, **\\--binary** | For unsigned binary numbers e.g. `0b0110`. |\n| **-d**, **\\--date** | For dates e.g. `2022-10-25`. |\n| **-i**, **\\--ipv4** | For IPv4 addresses e.g. `127.0.0.1`. |\n| **-I**, **\\--ipv6** | For IPv6 addresses e.g. `::1`. |\n| **-m**, **\\--mac** | For MAC addresses e.g. `00:12:34:ab:cd:ef`. |\n\n#### Other Optional Arguments\n\n| Option | Description                                                    |\n| ------ |:--------------------------------------------------------------:|\n| **FILE** | Optional input file. Stdin is used by default, can't be a tty. |\n| **-s**, **\\--size** | Output the range size as third column. |\n| **-f**, **\\--force** | Ignore parsing errors like malformed IPv6 addresses. |\n| **-h**, **\\--help** | Print the help message. |\n| **-v**, **\\--version** | Print version, copyright and license information. |\n\nFor more information refer to the help message with `-h/--help` or the\nmanpage with\n```bash\nman ranges\n```\n\n### EXAMPLES\n```bash\n$\u003e printf '1\\n2\\n2\\n3\\n6\\n7\\n8\\n' | ranges\n1 2\n3 4\n$\u003e\n$\u003e printf '1.0.0.1\\n1.0.0.2\\n1.1.1.1\\n' | ranges --ipv4\n1.0.0.1 1.0.0.2\n1.1.1.1 1.1.1.1\n$\u003e\n```\n\n## Building\n\n### Dependencies\nOn Ubuntu and Debian the following command should install all those build\ndependencies:\n```bash\nsudo apt install -y build-essential gcc-11 pandoc valgrind lintian\n```\nWhat all these are needed for is explained in the following sections.\n\n### Binary\n**ranges** uses nothing more than the C standard library so to build the binary\nyou need `make` and `gcc-11`. Version 11 is required because we use all\nsecurity flags recommended by\nhttps://airbus-seclab.github.io/c-compiler-security/gcc_compilation.html\n, some of which are only available since that version. To build the binary\nrun:\n```bash\nmake\n```\n\n### Tests\nOur extensive test suite is based on `bats`, which is however supplied as git\nsubmodule so doesn't need to be installed, but initialized:\n```bash\ngit submodule init\n```\nAll tests are run with and without `valgrind`'s `memcheck` tool. You can\nrun all tests with:\n```bash\nmake tests\n```\nNote that even though the tests are run in parallel, it might still take\na moment to run through all of them.\n\n### Manpage\nYou can build the manpage with `pandoc` using:\n```bash\nmake docs\n```\n\n### Deb Package\nTo pack the `deb` package use:\n```bash\nmake deb\n```\nTo run `lintian` on the debian package run use:\n```bash\nmake deb-tests\n```\n\n## Remarks\n\n### Use Cases\nIn case you wonder when this program might be useful, let me give you a short\nexample: I work in data center on a system consisting of a larger number of\nservers. Their different IP addresses are configured statically and also\ncontained in the `/etc/hosts` of our management machine. Unfortunately, the way\nwe initially assigned the addresses to the different types of nodes (compute,\ngpu, ...) turned out not to be very scalable, when we got a huge bunch of new\nservers. Our subnet was a mess in terms of fragmentation and finding the\nstill free addresses manually would have been tedious. We wondered whether\nthere was any command line tool that could summarize the list of IP addresses\nfrom the `/etc/hosts` into address ranges, so we could easily find the gaps.\nWhile it didn't take more than a few minutes to program a small Python script\nthat would do just that, at least for IPv4 addresses, I was surprised that I\ncouldn't find any general command line tool for the job.\n\n### Performance\nIt is obviously more convenient to have a ready to use command line tool that\nsupports different types of lists, instead of scripting a new one anytime\nsome problem like the one described above comes up, **ranges** is written in C\nand therefore also much faster. A short runtime comparison with a Python\nscript similar to my first one on a large IPv4 address list (10 million\nentries) gives the following results:\n```bash\n$\u003e make perf-comparison\n./scripts/perf-comparison.sh\nipranges.py: 29.188s\nranges -i: 0.836s\nOK: ranges is more than 20 times faster than ipranges.py\n$\u003e\n```\n\n## License\nThis code is distributed under [GPLv3](LICENSE) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgierens%2Franges","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgierens%2Franges","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgierens%2Franges/lists"}