IPv4 addresses are 32 bits wide, and thus the size of the address space is 232, or 4,294,967,296. However, this is only a theoretical upper-bound. It is not an accurate representation of all the addresses that may actually be used on the public internet.
For the purposes of this challenge, it is assumed that all addressing is classful. In reality, classful subdivision of address space has been superseded by CIDR (Classless Inter-Domain Routing and VLSM (Variable Length Subnet Masking), but this is ignored for this challenge.
According to the classful address scheme, there are 3 classes:
- Class A -
0.0.0.0
to127.255.255.255
with/8
netmask length - Class B -
128.0.0.0
to191.255.255.255
with/16
netmask length - Class C -
192.0.0.0
to223.255.255.255
with/24
netmask length
Classes D (multicast) and E (reserved) are also defined, but these are not used for public unicast addresses.
Each class is subdivided into networks according to the netmask for that class.
Thus 3.0.0.0
is an example of a Class A network. The netmask length for Class A is 8, so the full address space for this network is 3.0.0.0
to 3.255.255.255
. However, the first address (3.0.0.0
) is reserved as the network address and the last address (3.255.255.255
) is reserved as the broadcast address for that network. Thus the actual range of usable addresses is 3.0.0.1
to 3.255.255.254
which is 224 - 2 (= 16,777,214) total addresses.
Similarly, 200.20.30.0
is an example of a Class C network. The netmask length for Class C is 24, so the full address space for this network is 200.20.30.0
to 200.20.30.255
. Removing the network and broadcast addresses leaves the actual range of usable addresses is 200.20.30.1
to 200.20.30.254
which is 28 - 2 (= 254) total addresses.
There are further limitations on address ranges that may be used for public unicast. According to RFC 6890, the disallowed ranges are:
0.0.0.0/8
- Local networking10.0.0.0/8
- Private-Use100.64.0.0/10
- Shared Address Space127.0.0.0/8
- Loopback169.254.0.0/16
- Link Local172.16.0.0/12
- Private-Use192.0.0.0/24
- IETF Protocol Assignments192.0.2.0/24
- Reserved for use in documentation192.88.99.0/24
- 6to4 Relay Anycast192.168.0.0/16
- Private-Use198.18.0.0/15
- Benchmarking198.51.100.0/24
- Reserved for use in documentation203.0.113.0/24
- Reserved for use in documentation
Note that the above list uses VLSR netmasks to efficiently specify a range. In all but one cases, the given mask length has specificity is less than or equal to the normal classful mask length for the start of the range. Thus each of these VLSR ranges is equivalent to one or more classful networks. E.g. 172.16.0.0/12
is equivalent to the Class B networks 172.16.0.0
to 172.31.0.0
or the address range 172.16.0.0
to 172.31.255.255
.
The exception to this rule is the 100.64.0.0/10
VLSR range, which is more specific than the containing 100.0.0.0
Class A range. Thus 100.0.0.0
will be handled like other Class A ranges with the exception that it has a 4,194,304-address hole in the middle. The valid addresses in this Class A range will be 100.0.0.0
to 100.63.255.255
and 100.128.0.0
to 100.255.255.254
, a total of 224 - 222 - 2 (= 12,582,910) total addresses.
The goal of this challenge is to output all Class A, B and C unicast IPv4 addresses that may be validly assigned to a public internet host (i.e. excluding those detailed above).
No input will be given and should not be expected.
Output may be in any form convenient for your language, e.g. array, list, delimited string. Addresses must be output in standard dotted decimal format.
Output order does not matter.
Builtins that specifically give the required ranges of addresses are disallowed. Similarly any methods to dynamically inspect a BGP (or other protocol) routing table for the public internet are disallowed.
The numerically lowest address will be 1.0.0.1
and the numerically highest will be 223.255.255.254
.
This challenge is similar to Print out all IPv6 addresses, but because of the restrictions should require non-trivially different implementation.