Scroll to navigation

IPCALC-NG(1) General Commands Manual IPCALC-NG(1)

NAME

ipcalc-ng - Perform simple operations on IP addresses and networks

SYNOPSIS

ipcalc-ng [OPTION]... IP address[/prefix] [netmask]

Description

ipcalc-ng provides a simple way to calculate IP information for a host or network. Depending on the options specified, it may be used to provide IP network information in human readable format, in a format suitable for parsing in scripts, generate random private addresses, resolve an IP address, or check the validity of an address.

The options select what ipcalc-ng prints: by default, or with --info or --all-info, a summary of the network; with specific info options (e.g., --prefix), only those values. The --format option selects how it is printed, as described in the Output format section. Multiple options may be specified. It is required to specify an IP address; several operations require a netmask or a CIDR prefix as well.

Output format

The --format=FORMAT option selects one of these formats:

  • human Titled lines, as in the summary. Colors are used only when the output is a terminal and the NO_COLOR environment variable is not set. This is the default for the summary and for --split, --split-hosts, --deaggregate and --binary.
  • shell VAR=VALUE lines that can be passed to the shell's eval; a value that contains characters special to the shell, such as a space, is quoted and escaped. This is the default for the specific info options.
  • json A JSON object, whose values are all strings or arrays of strings.
  • value The values only, one per line; a value that would be quoted in the shell format keeps its quotes.

Each format applies to whatever is selected: the summary, or exactly the values of the specific info options, e.g., "ipcalc-ng --format=json -n -m 192.168.1.5/24" prints only NETWORK and NETMASK. The specific info options accept all four formats; the formats each operation accepts are given in its description.

Scripts should always pass --format, so that their output does not depend on the defaults.

Options

  • -c, --check Checks whether this is a valid IP address. When an IP family is specified only the addresses of that family are accepted. A zero exit status indicates a well formed address and a non-zero exit status indicates a malformed address. --format is ignored.
  • --equals=NET, --subnet-of=NET, --overlaps=NET Compare the provided network with NET and print the result, such as "The networks overlap" or "192.168.0.0/24 is a subnet of 192.168.0.0/23"; nothing is printed with --silent. --equals holds if both have the same network address and prefix, --subnet-of if every address of the network is in NET (equal networks included), and --overlaps if the two share at least one address; for CIDR networks the latter holds exactly when one is a subnet of the other. Host bits are ignored, and NET is given in the same form as the provided address, with an optional prefix or netmask after a slash. Networks of different families never compare true. The exit status is 0 when the comparison holds, 1 when it does not, and 2 on any error, such as a malformed address. Only one comparison may be given, and not together with --check. The only format accepted is human. Example "ipcalc-ng 192.168.0.1/24 --subnet-of=192.168.0.0/23".
  • -i, --info Display basic information on the provided network in human readable format, in a short summary, plus the fields of any specific info options given (e.g., --reverse-dns). This is the default option if no other options are provided. The formats accepted are human, shell and json; with --format, the specific info options other than --lookup-host cannot be given.
  • --all-info Display all the information ipcalc-ng can determine on the provided network and addresses in human readable format, which may be long. That includes geographic information, but not the hostname, which requires a DNS lookup (see --hostname). The formats accepted are as for --info.
For an IPv6 unicast address it also prints the interface identifier, i.e., the low 64 bits of the address, unless they are all zero or the address lies in ::/3. When the interface identifier is a Modified EUI-64 (it contains ff:fe in its middle octets), it prints the EUI-64, the MAC address it was derived from, whether that MAC address is universally (UAA) or locally (LAA) administered (MAC scope: universal or local), and whether it is an individual or group address (MAC type). These fields are not derived from other interface identifiers, such as stable privacy or temporary addresses, whose bits carry no such meaning (RFC 7136).
•
-S, --split=[COUNT:]PREFIX Split the provided network using the specified prefix or netmask. That is, split up the network into smaller chunks of a specified prefix. The formats accepted are human, json and value; with value, only the split networks are printed, one per line. Example "ipcalc-ng -S 26 192.168.1.0/24".
The option can be repeated to split the network into subnets of different sizes, also known as a VLSM (variable-length subnet mask) split. Each request of the form COUNT:PREFIX asks for COUNT subnets of the given prefix or netmask, and at most one request without a count takes all the space that remains. Requests are allocated from the start of the network, the largest subnets first, while the subnets are printed in the order of the requests. Space that is not allocated to any request is printed as unused networks, except with --format=value. If the network is too small for the requests, nothing is printed and the exit status is 1. Example "ipcalc-ng -S 1:58 -S 64 2001:db8:1c88:6000::/56".
  • --split-hosts=N1,N2,... Split the provided network into subnets that hold N1, N2, ... hosts, one subnet for each count. Each subnet is the smallest that holds the hosts; for IPv4 that includes the network and broadcast addresses (e.g., 10 hosts need a /28). The subnets are allocated as with --split and printed with their details, followed by the needed size, the used network and the unused networks. The values are those of the split of the Debian ipcalc-ng (its -s option), except that IPv6 networks are supported, a host count of 0 is rejected, and if the network is too small for the requests, nothing is printed and the exit status is 1. It cannot be combined with --split. The formats accepted are as for --split. Example "ipcalc-ng --split-hosts=10,20,30 192.168.0.0/24".
  • -d, --deaggregate Deaggregates the provided address range. That is, print the networks that cover the range. The range is given using the '-' separator, e.g., "192.168.1.3-192.168.1.23". The formats accepted are human, json and value; with value, only the networks are printed, one per line.
  • --binary Displays the bits of the provided address or, when a prefix is given, the bits of the network part of the network; any host bits set in the address are ignored. By default it prints each octet of an IPv4 address, or each 16-bit group of an IPv6 address, above its bits, marks the host bits with 'x', and brackets the network and host parts with UTF-8 box-drawing characters. An IPv6 address is printed in two halves, or on a single line when the output is at least 135 columns wide (see COLUMNS). All four formats are accepted; with value, only the bits of the network are printed, as in NETWORK, e.g., "11000000101010000000000000000000" for 192.168.0.0/16. The variables exposed are the addresses of the output, each as all of its bits: ADDRESS when no prefix shorter than the address is given; otherwise PREFIX followed, for IPv4, by ADDRESS, NETMASK, NETWORK, HOSTMIN, HOSTMAX and BROADCAST (for a /31, without NETWORK and BROADCAST), and for IPv6 by NETWORK. The bits are not part of the summary, and the option cannot be combined with other operations or with the specific info options.
  • -r, --random-private Generate a random private address using the supplied prefix or mask. By default it displays output in human readable format, but may be combined with other options (e.g., --network) to display specific information in VAR=VALUE format.
  • -h, --hostname Display the hostname for the given IP address. The address must be a single address; a network (e.g., "127.0.0.1/8") is rejected. The variable exposed is HOSTNAME.
  • -o, --lookup-host=NAME Display the IP address for the given hostname. With --info or --all-info, display the summary of that address instead. The variable exposed is ADDRESS.
  • -4, --ipv4 Explicitly specify the IPv4 address family.
  • -6, --ipv6 Explicitly specify the IPv6 address family.
  • -b, --broadcast Display the broadcast address for the given IP address and netmask. The variable exposed is BROADCAST (if available).
  • -a, --address Display the IP address for the given input. The variable exposed is ADDRESS (if available).
  • -g, --geoinfo Display geographic information for the given IP address. This option requires libmaxminddb to be available, and is not accepted when ipcalc-ng is built without it. The variables exposed are CONTINENT, COUNTRYCODE, COUNTRY, CITY, POSTALCODE, COORDINATES (latitude,longitude), ACCURACYRADIUS, TIMEZONE (e.g., Europe/Athens), ASN, ASORG, ASNETWORK and GEONETWORK (when available). ASN is the number of the autonomous system that routes the address on the Internet, i.e., the network of a single operator such as an ISP, a hosting provider or a company, and ASORG is the name of the organization that operates it (e.g., ASN=1241 and ASORG=Forthnet; "Routed by AS" and "Operated by" in the summary). They come from the GeoLite2 ASN database, when it is installed. ASNETWORK is the network, in CIDR notation, for which that database holds them; as the database is built from routing data, it approximates the network the autonomous system announces, e.g., the allocation of the ISP to which the address belongs. GEONETWORK is the network, in CIDR notation, for which the database holds the printed values. When the database has no country for the address, COUNTRY and COUNTRYCODE are the country its users represent (e.g., for a military base) or, without one, the country in which the network is registered. ACCURACYRADIUS is the accuracy of COORDINATES, as a radius in kilometers around them within which the address is likely to be. The summary output prints it with its unit, e.g., "Accuracy: 200 km". For a network, a value is printed only when the database knows it for the whole network, not just for the given address.
  • -m, --netmask Calculate the netmask for the given IP address. If no mask or prefix is provided, in IPv6 a 128-bit mask is assumed, while in IPv4 it assumes that the IP address is in a complete class A, B, or C network. Note, however, that many networks no longer use the default netmasks in IPv4. The variable exposed is NETMASK.
  • --wildcard Display the wildcard mask, the inverse of the netmask that Cisco ACLs and OSPF use, e.g., "0.0.0.255" for a /24 network. It applies to IPv4 only; nothing is printed for IPv6. The variable exposed is WILDCARD. The summary shows it with --all-info.
  • -p, --prefix Show the prefix for the given mask/IP address. The variable exposed is PREFIX.
  • --class-prefix Assign the netmask of the provided IPv4 address based on the address class. This was the default in previous versions of this software.
  • -n, --network Display the network address for the given IP address and netmask. The variable exposed is NETWORK.
  • --cidr Display the network address and the prefix in CIDR notation, e.g., "192.168.123.0/24". The prefix is included for a single address too. The variable exposed is CIDR. For example, "ipcalc-ng -r 24 --cidr --format=value" prints a random private network.
  • --reverse-dns Display the reverse DNS for the given IP address and netmask. Reverse DNS domains for IPv6 (RFC 3596) can only be delegated at 4-bit boundaries, so for an IPv6 prefix that is not a multiple of 4 the network is covered by up to 8 domains, which are all printed. In that case the REVERSEDNS variable holds a quoted, space-separated list, and with --format=value each domain is printed on its own line. The summary shows it with --all-info, and in JSON REVERSEDNS is always an array. The variable exposed is REVERSEDNS.
  • --minaddr Display the minimum host address in the provided network. The variable exposed is MINADDR.
  • --maxaddr Display the maximum host address in the provided network. The variable exposed is MAXADDR.
  • --addresses Display the number of host addresses in the provided network. The variable exposed is ADDRESSES.
  • --addrspace Display address space allocation information for the provided network. The variable exposed is ADDRSPACE.
  • --format=FORMAT Print the output as human, shell, json or value; see the Output format section.
  • -s, --silent Don't ever display error messages, nor the result of a comparison.

Deprecated options

These options are kept for compatibility with earlier versions. On a terminal, ipcalc-ng prints a hint that names the replacement.

  • -j, --json Print the summary as a JSON object, even when specific info options are given, which only add their values to it; with --split, --split-hosts, --deaggregate and --binary print JSON, and with the comparison options print nothing. Use --format=json, which prints only the selected values.
  • --no-decorate Print the values of the specific info options, or the networks of --split, --split-hosts and --deaggregate, without titles; print the summary without colors; and with the comparison options print nothing. It is ignored when -j is given, and cannot be used with --binary. Use --format=value, or for the summary --format=human with the NO_COLOR environment variable set.

Environment

  • NO_COLOR When set, to any value, the human format is printed without colors, even on a terminal.
  • COLUMNS The width of the output in columns. With --binary, an IPv6 address is printed on a single line when it is 135 or more, and in two halves otherwise, e.g., "COLUMNS=135 ipcalc-ng --binary 2001:db8::/48". When unset, the width of the terminal is used, or 80 when the output is not a terminal.

Examples

Display all information of an IPv4

$ ipcalc-ng --all-info 193.92.150.2/24
Address:        193.92.150.2
Network:        193.92.150.0/24
Netmask:        255.255.255.0 = 24
Wildcard:       0.0.0.255
Broadcast:      193.92.150.255
Reverse DNS:    150.92.193.in-addr.arpa.
Address space:  Internet
Address class:  Class C
HostMin:        193.92.150.1
HostMax:        193.92.150.254
Hosts/Net:      254
Country code:   GR
Country:        Greece

Display information in key-value format

$ ipcalc-ng --format=shell -pnmb --minaddr --maxaddr --geoinfo --addrspace 193.92.150.2/255.255.255.224
NETWORK=193.92.150.0
NETMASK=255.255.255.224
PREFIX=27
BROADCAST=193.92.150.31
ADDRSPACE=Internet
MINADDR=193.92.150.1
MAXADDR=193.92.150.30
COUNTRYCODE=GR
COUNTRY=Greece

Display all information of an IPv6

$ ipcalc-ng --all-info 2a03:2880:20:4f06:face:b00c:0:14/64
Full Address:   2a03:2880:0020:4f06:face:b00c:0000:0014
Address:        2a03:2880:20:4f06:face:b00c:0:14
Full Network:   2a03:2880:0020:4f06:0000:0000:0000:0000/64
Network:        2a03:2880:20:4f06::/64
Netmask:        ffff:ffff:ffff:ffff:: = 64
Reverse DNS:    6.0.f.4.0.2.0.0.0.8.8.2.3.0.a.2.ip6.arpa.
Address space:  Global Unicast
Interface ID:   face:b00c:0000:0014
HostMin:        2a03:2880:20:4f06::
HostMax:        2a03:2880:20:4f06:ffff:ffff:ffff:ffff
Hosts/Net:      2^(64) = 18446744073709551616
Country code:   IE
Country:        Ireland
$ ipcalc-ng --all-info fe80::21b:21ff:fe3a:5c7d/64
Full Address:   fe80:0000:0000:0000:021b:21ff:fe3a:5c7d
Address:        fe80::21b:21ff:fe3a:5c7d
Full Network:   fe80:0000:0000:0000:0000:0000:0000:0000/64
Network:        fe80::/64
Netmask:        ffff:ffff:ffff:ffff:: = 64
Reverse DNS:    0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa.
Address space:  Link-Scoped Unicast
Interface ID:   021b:21ff:fe3a:5c7d
EUI-64:         00:1b:21:ff:fe:3a:5c:7d
MAC address:    00:1b:21:3a:5c:7d
MAC scope:      universal
MAC type:       individual
HostMin:        fe80::
HostMax:        fe80::ffff:ffff:ffff:ffff
Hosts/Net:      2^(64) = 18446744073709551616

Display JSON output

$ ipcalc-ng --all-info --format=json 2a03:2880:20:4f06:face:b00c:0:14/64
{

"FULLADDRESS":"2a03:2880:0020:4f06:face:b00c:0000:0014",
"ADDRESS":"2a03:2880:20:4f06:face:b00c:0:14",
"FULLNETWORK":"2a03:2880:0020:4f06:0000:0000:0000:0000",
"NETWORK":"2a03:2880:20:4f06::",
"NETMASK":"ffff:ffff:ffff:ffff::",
"PREFIX":"64",
"CIDR":"2a03:2880:20:4f06::/64",
"REVERSEDNS":[
"6.0.f.4.0.2.0.0.0.8.8.2.3.0.a.2.ip6.arpa."],
"ADDRSPACE":"Global Unicast",
"INTERFACEID":"face:b00c:0000:0014",
"MINADDR":"2a03:2880:20:4f06::",
"MAXADDR":"2a03:2880:20:4f06:ffff:ffff:ffff:ffff",
"ADDRESSES":"18446744073709551616",
"COUNTRYCODE":"IE",
"COUNTRY":"Ireland",
"COORDINATES":"53.000000,-8.000000" }

Split a network into subnets of different sizes

$ ipcalc-ng -S 1:28 -S 2:27 192.168.0.0/24
[Split networks]
Network:        192.168.0.64/28
Network:        192.168.0.0/27
Network:        192.168.0.32/27
Total:          3
[Unused networks]
Network:        192.168.0.80/28
Network:        192.168.0.96/27
Network:        192.168.0.128/25

Split a network into subnets for a number of hosts

$ ipcalc-ng --split-hosts=10,20 192.168.0.0/24
[Split networks]
1. Requested size: 10 hosts
Network:        192.168.0.32/28
Netmask:        255.255.255.240 = 28
Broadcast:      192.168.0.47
HostMin:        192.168.0.33
HostMax:        192.168.0.46
Hosts/Net:      14
2. Requested size: 20 hosts
Network:        192.168.0.0/27
Netmask:        255.255.255.224 = 27
Broadcast:      192.168.0.31
HostMin:        192.168.0.1
HostMax:        192.168.0.30
Hosts/Net:      30
Total:          2
Needed size:    48
Used network:   192.168.0.0/26
[Unused networks]
Network:        192.168.0.48/28
Network:        192.168.0.64/26
Network:        192.168.0.128/25

Split an IPv6 prefix into one /58 and /64 networks in the remaining space

$ ipcalc-ng --format=value -S 1:58 -S 64 2001:db8:1c88:6000::/56
2001:db8:1c88:6000::/58
2001:db8:1c88:6040::/64
2001:db8:1c88:6041::/64
...
2001:db8:1c88:60ff::/64

Display the bits of a network

$ ipcalc-ng --binary 192.168.92.6/22
Network:    192.168.92.0/22

192. 168. 92-95. 0-255
11000000.10101000.010111xx.xxxxxxxx
└──── network /22 ─────┘└ host 10 ┘ Address: 192.168.92.6 11000000.10101000.01011100.00000110 Netmask: 255.255.252.0 11111111.11111111.11111100.00000000 Network: 192.168.92.0 11000000.10101000.01011100.00000000 HostMin: 192.168.92.1 11000000.10101000.01011100.00000001 HostMax: 192.168.95.254 11000000.10101000.01011111.11111110 Broadcast: 192.168.95.255 11000000.10101000.01011111.11111111

Check whether a network is a subnet of another

$ ipcalc-ng 192.168.0.1/24 --subnet-of=192.168.1.15/23
192.168.0.0/24 is a subnet of 192.168.0.0/23

Check whether a network overlaps any network in a list

$ while read net; do
>   ipcalc-ng -s 10.20.0.0/16 --overlaps="$net"
>   case $? in 0) echo "conflict: $net" ;; 2) echo "bad entry: $net" ;; esac
> done < networks.txt

Lookup of a hostname

$ ipcalc-ng --format=value --lookup-host localhost
::1

IPv4 lookup of a hostname

$ ipcalc-ng --format=value --lookup-host localhost -4
127.0.0.1

Reverse lookup of a hostname

$ ipcalc-ng --format=value -h 127.0.0.1
localhost

Use the values in a shell script

$ eval "$(ipcalc-ng --format=shell -n -p 192.168.1.5/24)"
$ echo "$NETWORK/$PREFIX"
192.168.1.0/24

Authors

  • Nikos Mavrogiannopoulos n.mavrogiannopoulos@gmail.com
  • Erik Troan ewt@redhat.com
  • Preston Brown pbrown@redhat.com
  • David Cantrell dcantrell@redhat.com

Reporting Bugs

Report bugs at https://gitlab.com/ipcalc/ipcalc/issues

Copyright

Copyright © 1997-2024 Red Hat, Inc. Copyright © 2020-2024 Nikos Mavrogiannopoulos This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

October 2026