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 -
- Class B -
- Class C -
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.
188.8.131.52 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
184.108.40.206. However, the first address (
220.127.116.11) is reserved as the network address and the last address (
18.104.22.168) is reserved as the broadcast address for that network. Thus the actual range of usable addresses is
22.214.171.124 which is 224 - 2 (= 16,777,214) total addresses.
126.96.36.199 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
188.8.131.52. Removing the network and broadcast addresses leaves the actual range of usable addresses is
184.108.40.206 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 networking
100.64.0.0/10- Shared Address Space
169.254.0.0/16- Link Local
192.0.0.0/24- IETF Protocol Assignments
192.0.2.0/24- Reserved for use in documentation
220.127.116.11/24- 6to4 Relay Anycast
198.51.100.0/24- Reserved for use in documentation
203.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.31.0.0 or the address range
The exception to this rule is the
100.64.0.0/10 VLSR range, which is more specific than the containing
18.104.22.168 Class A range. Thus
22.214.171.124 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
126.96.36.199, 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
188.8.131.52 and the numerically highest will be
This challenge is similar to Print out all IPv6 addresses, but because of the restrictions should require non-trivially different implementation.