[HN Gopher] Ipcalc - Command line CIDR calculator with IPv6 support
___________________________________________________________________
Ipcalc - Command line CIDR calculator with IPv6 support
Author : jaden
Score : 71 points
Date : 2022-07-31 13:38 UTC (9 hours ago)
(HTM) web link (gitlab.com)
(TXT) w3m dump (gitlab.com)
| c7DJTLrn wrote:
| Any idea why it doesn't give a HostMin/HostMax/Hosts field when
| passing an IPv6 range? $ ipcalc
| 2600:1ff2:4000::/40 Address: 2600:1ff2:4000::
| 0010011000000000:0001111111110010:0100000000000000:00000000000000
| 00:0000000000000000:0000000000000000:0000000000000000:00000000000
| 00000 Netmask: 40 1111
| 111111111111:1111111111111111:1111111100000000:0000000000000000:0
| 000000000000000:0000000000000000:0000000000000000:000000000000000
| 0 Prefix: 2600:1ff2:4000::/40 00100110
| 00000000:0001111111110010:0100000000000000:0000000000000000:00000
| 00000000000:0000000000000000:0000000000000000:0000000000000000
| peppermint_tea wrote:
| shameless plug, I made an ipcalc6 in rust that does it (with
| colors)
|
| https://github.com/ba9f11ecc3497d9993b933fdc2bd61e5/ipcalc6
|
| user@box:~/Documents/code/rust/ipcalc6$ cargo run
| 2600:1ff2:4000::/40 Finished dev [unoptimized
| + debuginfo] target(s) in 0.01s Running
| `target/debug/ipcalc6 '2600:1ff2:4000::/40'`
|
| WARNING : netmask /40 is smaller than /48, this is unusual if
| ip of type : Global Unicast Address and Link-Local Address
|
| Type: Unicast Global
|
| Address: 2600:1ff2:4000:0000:0000:0000:0000:0000
|
| NetMask: 40
|
| Hosts/Net: 19342813113834066795298816
|
| Address: 0010011000000000.0001111111110010.0100000000000000.000
| 0000000000000.0000000000000000.0000000000000000.000000000000000
| 0.0000000000000000
|
| NetMask: 1111111111111111.1111111111111111.1111111111111111.000
| 0000000000000.0000000000000000.0000000000000000.000000000000000
| 0.0000000000000000
|
| HostMin: 0010011000000000.0001111111110010.0100000000000000.000
| 0000000000000.0000000000000000.0000000000000000.000000000000000
| 0.0000000000000000
|
| HostMax: 0010011000000000.0001111111110010.0100000000000000.111
| 1111111111111.1111111111111111.1111111111111111.111111111111111
| 1.1111111111111111
| zamadatix wrote:
| "HostMin" = Prefix.
|
| "HostMax" = Prefix followed by all f's.
|
| "Hosts" = some ungodly large number (i.e. "small" for this is
| 2^64) you typically don't care about anymore.
|
| If someone did something atypical like use a /123 (mask >64,
| mask not a multiple of 4) and you do actually want to see host
| max and host count as a result you can pass "--all-info".
| Otherwise a combination of the ridiculous size and hex encoding
| makes everything but "what is the prefix and netmask"
| irrelevant.
| nilespotter wrote:
| nickjj wrote:
| If you're only interested in the total number of hosts within a
| CIDR block for IPv4 addresses you can do this Python 1 liner:
| python3 -c "import ipaddress;
| print(ipaddress.ip_network('10.0.0.0/16').num_addresses)"
|
| You could turn that into a shell function that takes a CIDR block
| as input if you wanted an alias-like shortcut.
|
| While I didn't cover this function specifically, I did recently
| create an IP address allow list with CIDR block support in Python
| and found myself exploring the ipaddress module. It's pretty
| useful to determine things like if an IP address is in a specific
| range, etc.. I ended up making a blog post and video about it
| here: https://nickjanetakis.com/blog/create-an-ip-address-allow-
| li...
| zamadatix wrote:
| I use both JS and Python for networking all the time and
| sometimes I wish there was just a first class way to say "these
| are u32" and "these are u128" because it can make things like
| this dead simple and blazing fast (pseudocode):
| function <u1> inSubnet(<u32>networkAddress, <u32>networkMask,
| <u32>testIP) { <u32>lower = networkAddress;
| <u32>upper = networkAddress + ~netmask;
| return (testIP >= lower) && (testIP <= upper); }
|
| Number of IPs in a subnet is "~netmask + 1", network address of
| a host with a given netmask is "host & netmask", mask length to
| integer form is "0xFFFFFFFF << (32 - maskLength)", and so on.
| Subnet logic is all designed to be clear, lightweight, and fast
| from the ground up.
|
| Of course it's also nice to have built in libraries like
| "ipaddress" too as most (if not all) of what you were wanting
| to do will likely already be done for you but in the cases it
| doesn't you're back to wishing you could just specify a type to
| save a lot of work.
| teaearlgraycold wrote:
| Agreed. Python defaulting to magic bigints is nice when
| you're in a math domain, but terrible when in a computer
| domain. The stdlib really needs some nice simple u32(), i64()
| etc. constructors.
| borlox wrote:
| lol, it shows address classes. If I was in kindergarten when
| classes became deprecated, I could be a grandfather by now.
| zamadatix wrote:
| What, no shock about it having IPv4 support even though that
| was replaced when you were in 2nd grade :p.
| luckman212 wrote:
| I discovered this tool years ago and it's been very useful, but
| difficult to build on macOS. I filed an issue[0] that remains
| open.
|
| Not sure if things have changed since then.
|
| [0]: https://gitlab.com/ipcalc/ipcalc/-/issues/20
| traceroute66 wrote:
| Minor moan... such a shame the tool is written in C and not Rust
| or Go.
|
| Instead of being able to compile out of the box, I've seemingly
| got to install some tools I've never heard of (mesa and ninja).
| They could have at least allowed you to compile using bog-
| standard make.
| jeroenhd wrote:
| It's just a matter of what tools you happen to have
| preinstalled. Meson and Ninja are easier to install than the
| entire Rust suite or Go (using their official guide, anyway).
| They're in the standard repos rather than piping curl to bash
| or manually managing tar.gz downloads.
|
| I would appreciate a Makefile for a project this simple but I
| do prefer the Meson/Ninja build system for projects like these.
| steveklabnik wrote:
| Which "standard repos" don't contain the Go or Rust compiler
| these days? All the major distros have both, as far as I
| know.
| jeroenhd wrote:
| The Rust documentation recommends "curl --proto '=https'
| --tlsv1.2 -sSf https://sh.rustup.rs | sh" unless you're on
| Windows. The Go website tells you to download a tar.gz and
| extract it into your path. To me, that signals that you're
| not supposed to use your package manager to install the
| tooling (or face the incompatibility wrath if you try to do
| so anyway).
|
| In comparison, both Meson and Ninja refer you to your
| package manager as a way to install them.
| traceroute66 wrote:
| > easier to install than Go
|
| Huh?!?!?!
|
| I don't know about Rust (I know they like their install
| script), but for Go you can download a pre-compiled binary
| and you're instantly up and running. That option is not
| exactly hidden[1].
|
| You don't even have to use an OS installer, e.g. for
| Linux/Mac you can download a .tar.gz file[1] unzip it
| anywhere and just run "go" based commands to compile stuff
| immediately (maybe adding it to your $PATH to make life
| easier).
|
| But really. Go is a million times quicker and smaller than
| usual bunch of stuff you need to install to get a C thing
| compiled (and that's just the standard tools, before we start
| talking about random stuff like Meson or Ninja)
|
| The point I was making is that Ipcalc is a simple CLI
| utility. It doesn't need all the baggage that comes with C
| compiling. Its practically made for Rust or Go.
|
| You can also easily cross-platform compile with Go. Try that
| with C without jumping through hoops !
|
| [1] https://go.dev/dl/
| broknbottle wrote:
| Lol you have to setup the necessary build directories
| bin,src,etc and environment variables before using golang
| from tarball e.g. GOROOT, GOPATH, GOPROXY=direct or you're
| gonna run into issues. Golang is easily the most
| overcomplicated when it comes to setup the of the dev
| environment.
| metadat wrote:
| It wasn't always like this, in the early days you only
| needed GOROOT and GOPATH. Nowadays there are numerous
| hidden envvar toggles like GOPROXY and GOMODULES111.
|
| Even still, this doesn't seem more difficult than
| installing and learning how to use ninja and / or meson
| build.
| jeroenhd wrote:
| Perhaps "install" is the wrong word.
|
| I want my software to be upgraded through the normal means.
| I don't want to monitor the Go website for new versions and
| I don't want the tools themselves to phone home with update
| checks (especially if Google is behind them).
|
| I now notice that Ubuntu packages golang-go in their
| repositories, so I suppose Go is on par with Meson and
| Ninja. Strange that they don't mention that on their
| download page, though.
|
| > You can also easily cross-platform compile with Go. Try
| that with C without jumping through hoops !
|
| Clang has "--target=arm-linux-gnueabihf" to cross compile
| to ARM. You might need to go more specific (i.e. "--
| target=riscv64 -march=rv64gc" for specific RISCV
| configurations) but it's just a single command line flag.
| With GCC/G++ you need the dedicated compiler packaged
| separately to save space, but you'd use environment
| variables (export CC="arm-linux-gnueabihf-gcc"; export
| CXX="export CC="arm-linux-gnueabihf-g++").
|
| The only difficulty you'd run into is when you want to
| dynamically link the produced binary (because you need a
| compatible .so to link against). You'll have the same
| problem in any language, though.
| wootest wrote:
| Slightly off-topic, but according to that page, the project has
| "-1246658 Bytes Project Storage".
| mdaniel wrote:
| Seems to be tracked by this, and its associated, issue:
| https://gitlab.com/gitlab-org/gitlab/-/issues/368326
| iso1631 wrote:
| Presumably the idea is to give a little more info than the
| standard jodie's ipcalc which comes with your OS, and far better
| ipv6 support?
|
| The examples don't make it clear what happens when you type
| "ipcalc 1.1.1.41/27", which I often do to find the top and bottom
| of a given /27 (or /29, or /26, etc). I'm not interested in
| typing
|
| "ipcalc -pnmb --minaddr --maxaddr --geoinfo --addrspace"
| sgjohnson wrote:
| alias iprange="ipcalc -pnmb --minaddr --maxaddr --geoinfo
| --addrspace"
| circularfoyers wrote:
| Last I checked (unless I missed something), this didn't have
| the ability to perform VLSM. Which is what I thought
| distinguished Jodie's tool from every other similar command
| line tool. Which is frustrating that this is what replaced
| Jodie's tool on Fedora.
| zamadatix wrote:
| This seems to do FLSM splitting via --split but I didn't even
| know VLSM was an option in Jodies, how does the syntax for
| that work?
| Reventlov wrote:
| [remy@typhoon:~]$ ipcalc 1.1.1.41/27
|
| Address: 1.1.1.41
|
| Network: 1.1.1.32/27
|
| Netmask: 255.255.255.224 = 27
|
| Broadcast: 1.1.1.63
|
| Address space: Internet
|
| HostMin: 1.1.1.33
|
| HostMax: 1.1.1.62
|
| Hosts/Net: 30
| nixcraft wrote:
| We have a script called ipcalc[1] has written in Perl on Linux
| and Unix. It takes an IPv4 address and netmask and calculates the
| resulting broadcast, network, Cisco wildcard mask, and host
| range. So this name is confusing, I guess.
|
| ]1] https://packages.debian.org/search?keywords=ipcalc
| lucb1e wrote:
| I always used `apt install sipcalc`, that does ipv6 just fine
| since years. Why another tool?
|
| It always seemed confusing that "sip calc" has nothing to do with
| SIP whatsoever, but then seeing "ipcalc" it's also quite the
| generic name and not any better for searching on.
|
| Edit: Was wondering who predates whom. Sipcalc had its last
| release in 2013; the earliest commit here is from 2015. I guess
| that settles the matter, don't need to find sipcalc's commit
| history :D. Anyway, I never noticed bugs in sipcalc and I'm also
| not missing any new features or anything.
| icehawk wrote:
| ipcalc is older than 2015, but it lived in a different
| repository:
|
| https://github.com/fedora-sysv/initscripts/commits/313773794...
|
| ipcalc gets removed here:
|
| https://github.com/fedora-sysv/initscripts/commit/76201baf7a...
|
| All in all it looks like ipcalc predates sipcalc by three years
| (1998 vs 2001)
| coderholic wrote:
| For another cli based IP address utility check out IPinfo.io's
| CLI: https://github.com/ipinfo/cli
|
| It doesn't currently support calculations, but it does support
| conversion of start-end ranges to CIDRs (via `range2cidr` and
| `cidr2range`) and `grepip`. If you just want to get details for
| an IP it's gives a great overview, and supports bulk lookup too:
| $ ipinfo 8.8.8.8 Core - IP 8.8.8.8
| - Anycast true - Hostname dns.google -
| City Mountain View - Region California
| - Country United States (US) - Location
| 37.4056,-122.0775 - Organization AS15169 Google LLC
| - Postal 94043 - Timezone America/Los_Angeles
| ASN - ID AS15169 - Name Google LLC
| - Domain google.com - Route 8.8.8.0/24 - Type
| business Company - Name Google LLC
| - Domain google.com - Type business
| Privacy - VPN false - Proxy false -
| Tor false - Relay false - Hosting false
| - Service Abuse - Address US, CA,
| Mountain View, 1600 Amphitheatre Parkway, 94043 -
| Country United States (US) - Email network-
| abuse@google.com - Name Abuse - Network
| 8.8.8.0/24 - Phone +1-650-253-0000
| kruptos wrote:
| I wish they had a hacker/developer pricing tier. I don't need
| 150k requests with their full feature set. I need 200/month.
| coderholic wrote:
| It's free for up to 50k req/month.
|
| EDIT: Ah, do you mean for the full data set, at lower request
| volumes? What hacker/dev price point for all data at low
| volumes do you think makes sense?
| metadat wrote:
| 1000/mo. for free? Could be a good conversion funnel got
| paid accounts. Any serious user will naturally graduate to
| requiring a paid plan.
| elktea wrote:
| related, I like `sipcalc` for the great --v6split functionality
___________________________________________________________________
(page generated 2022-07-31 23:01 UTC)