37 comments

[ 0.25 ms ] story [ 93.0 ms ] thread
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"

alias iprange=“ipcalc -pnmb --minaddr --maxaddr --geoinfo --addrspace”
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.
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?
[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

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
I wish they had a hacker/developer pricing tier. I don't need 150k requests with their full feature set. I need 200/month.
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?

1000/mo. for free? Could be a good conversion funnel for paid accounts. Any serious user will naturally graduate to requiring a paid plan.
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.

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:0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000
  Netmask: 40                                      1111111111111111:1111111111111111:1111111100000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000
  Prefix:  2600:1ff2:4000::/40                     0010011000000000:0001111111110010:0100000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000
"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.

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.0000000000000000.0000000000000000.0000000000000000.0000000000000000.0000000000000000

NetMask: 1111111111111111.1111111111111111.1111111111111111.0000000000000000.0000000000000000.0000000000000000.0000000000000000.0000000000000000

HostMin: 0010011000000000.0001111111110010.0100000000000000.0000000000000000.0000000000000000.0000000000000000.0000000000000000.0000000000000000

HostMax: 0010011000000000.0001111111110010.0100000000000000.1111111111111111.1111111111111111.1111111111111111.1111111111111111.1111111111111111

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...

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.

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.
lol, it shows address classes. If I was in kindergarten when classes became deprecated, I could be a grandfather by now.
What, no shock about it having IPv4 support even though that was replaced when you were in 2nd grade :p.
> What, no shock about it having IPv4 support even though that was replaced when you were in 2nd grade :p.

IPv4 is still unfortunately relevant to almost every real world network, where address classes have been irrelevant to basically everyone for decades.

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.

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.

> 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/

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.

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.
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.

It's only two commands, clearly stated in the docs. No configuration required.

    meson setup build
    ninja -C build
It's not like meson or ninja is an obscure tool either, contrary to what this thread suggests. They're both popular C/C++ build tools along with cmake.
Which “standard repos” don’t contain the Go or Rust compiler these days? All the major distros have both, as far as I know.
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.

related, I like `sipcalc` for the great --v6split functionality