Print addresses in CIDR range.
Download the subnet shell
script to your ~/.local/bin
directory.
SUBNET_VERSION='v0.4.5'
wget -O ~/.local/bin/subnet "https://github.com/eetami/subnet/releases/download/${SUBNET_VERSION}/subnet"
chmod +x ~/.local/bin/subnet
subnet -h
This will also install files related to simpleargs
under your home directory in ~/.simpleargs.d/
.
$ subnet 192.168.201.1/30
192.168.201.0 (network address)
192.168.201.1 *
192.168.201.2
192.168.201.3 (broadcast address)
$ subnet -q 192.168.201.1/30
192.168.201.0
192.168.201.1
192.168.201.2
192.168.201.3
$ subnet -u 192.168.201.1/30
192.168.201.1 *
192.168.201.2
$ subnet -qud' ' 192.168.201.1/30
192.168.201.1 192.168.201.2
Print all addresses in 192.168.201.1/30
network as IPv4-mapped IPv6 addresses
$ subnet -m 192.168.201.1/30
0000:0000:0000:0000:0000:ffff:192.168.201.0 (network address)
0000:0000:0000:0000:0000:ffff:192.168.201.1 *
0000:0000:0000:0000:0000:ffff:192.168.201.2
0000:0000:0000:0000:0000:ffff:192.168.201.3 (broadcast address)
The -m
option can also be used in combination with other outputting options, such as -c
, -q
and -u
.
Print only usable addresses from above network as IPv4-mapped IPv6 addresses in standard canonical IPv6 format without additional details
$ subnet -cqumstandard 192.168.201.1/30
::ffff:c0a8:c901
::ffff:c0a8:c902
Since the -m
option accepts an optional argument, it must be used as the last flag in an option argument.
For example the following invocation will produce an error.
$ subnet -mc 192.168.201.1/30
ERROR: -m/--mapped: invalid value 'c'
Valid values are: 'false', 'default' and 'standard'.
Usage: subnet [OPTION]... <CIDR>
But the following invocation will work.
$ subnet -cm 192.168.201.1/30
::ffff:192.168.201.0 (network address)
::ffff:192.168.201.1 *
::ffff:192.168.201.2
::ffff:192.168.201.3 (broadcast address)
$ subnet -v6 dead::beef/64
dead:0000:0000:0000:0000:0000:0000:0000
dead:0000:0000:0000:ffff:ffff:ffff:ffff
$ subnet -cv6 dead::beef/126
dead::beec
dead::beed
dead::beee
dead::beef *
$ subnet -v6 -m ::ffff:c0a8:beef/126
192.168.190.236
192.168.190.237
192.168.190.238
192.168.190.239 *
$ subnet -v6 -cmstandard ::ffff:c0a8:beef/126
::ffff:192.168.190.236
::ffff:192.168.190.237
::ffff:192.168.190.238
::ffff:192.168.190.239 *
subnet requires simpleargs argument parser for bash.
If it is not present in user system, subnet will automatically download and install it (using
wget
or curl
, whichever is present) in user home directory.
However if the target system does not have internet access, or access to GitHub is blocked for some reason, then manual installation is required.
The simplest way is to copy the simpleargs-${version} script onto the target system and follow the simpleargs installation instructions.
subnet automatically creates a man page on first invocation (thanks to
simpleargs).
However the man page is not accessible by default, but it can be accessed by
modifying PATH
environment variable appropriately.
export PATH=${PATH}:${HOME}/.simpleargs.d/bin
man subnet
When you have a local installation of simpleargs — i.e. you have run the commands in
simpleargs installation instructions
manually — then PATH
is automatically appended and you can already access subnet man page.