I want to avoid responding to illegal or spoofed addresses. One type that's easy to detect is an address that should not exist on a packet received by my router: a special-use address.
Given an IPv4 32-bit address, identify whether it is valid general-use address.
- Special-use addresses, as defined by the Internet Engineering Task Force, are considered invalid.
- Special-use addresses are listed at https://en.wikipedia.org/wiki/IPv4#Special-use_addresses. A copy of the list (omitting explanatory columns) is below.
- Input will be a character sequence in the dot-decimal notation, consisting of four positive decimal numbers (called "octets") each in the range 0–255 separated by periods (e.g., 169.254.0.31). Each octet represents an 8-bit segment of the address.
- Output must indicate true or false, using any two indicators of your choice for true and false.
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
- Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
- 18.104.22.168 false
- 22.214.171.124 true
- 0.255.0.0 false
- 126.96.36.199 true
- 253.8.22.37 false
- 188.8.131.52 true
|Address Block||Address Range|
Note on address blocks. This is a shortcut method of listing an address range, called CIDR notation. The notation is four octets followed by a slash and a decimal number. The decimal number is the count of leading 1 bits in the network mask, and indicates how many leading bits in the underlying 32-bit address range are specified as fixed. For example, a mask of 24 indicates that only the last 8 bits of the address range vary. Thus writing 192.0.2.0/24 indicates that only the last octet varies. The range for 192.0.2.0/24 is 192.0.2.0–192.0.2.255.