This function will take an array of IPv4 addresses as ‘IP.IP.IP.IP’, ‘IP.IP.IP.IP/Masklength’ or ‘IP.IP.IP.IP/SM.SM.SM.SM’ and return a SubnetInformation object for each IP address supplied. The SubnetInformation contains the following properties:
- AddressValueSupplied (string) the exact string supplied to the function
- AddressFormatSupplied (string) the format calculated from matching the string: ADDRONLY, ADDRANDMASK, ADDRANDLEN or UNKNOWN
- AddressSpaceClassification (string) the supplied address’s place in the overall IPv4 space: Public, Private or reserved of several kinds
- Subnet (string) the subnet as dotted-decimal
- SubnetMask (string) the subnet mask as dotted-decimal
- SubnetMaskLength (int) the length of the subnet mask (0 to 32)
- IPAddress (string) the address calculated from the supplied string as dotted-decimal
- NumberOfHosts (int) the number of usable IP addresses in the subnet
- FirstHostAddress (string) the first usable host address as dotted-decimal
- LastHostAddress (string) the last usable host address as dotted-decimal
- BroadcastAddress (string) the broadcast address as dotted-decimal
- AddressClassification (string) the supplied address’s place in the subnet: Host, Subnet or Broadcast
- GeoInformation (GeoInformation) an object containing geoinformation about the specified address
Single address supplied logic
If only a single address, without any mask information, is supplied to the function, it will return:
- a Class A (/8), B (/16) or C (/24) subnet, if the address is from a private space
- a single address subnet (/32) otherwise
Long subnet logic
If a (/32) subnet mask is supplied, these properties all contain the address: Subnet, BroadcastAddress, IPAddress, FirstHostAddress, LastHostAddress
If a (/31) subnet mask is supplied, the result is as follows:
NumberOfHosts = 0
FirstHostAddress = $null
LastHostAddress = $null
AddressClassification = either ‘Subnet’ or ‘Broadcast’
GeoInformation
At the time of writing, the geo information about the IP address is obtained from IP-API.COM . Their free service is being used which imparts the following limitations:
- No SSL, http:// has to be used. However, since the argument is supplied in the URL, there is no additional danger of information disclosure due to the lack of encryption.
- a maximum of 45 requests per minute form the same IP address. The module function doing the querying does not process the throttling code (HTTP 429) and retry, but will simply throw a warning.