I am writing unit tests for a client library. I want to test connecting with an invalid port and an invalid ip. What is a good ip address to use that won't potentially be routed somewhere? I don't want to make any assumptions about the network the machine running the unit tests is on. LOCALHOST seems like a bad choice since that is the valid machine running the server component and I want to test an invalid port separately. Is there an INVALID-IP reserved somewhere in the IPv4 spec?
Reserved Addresses 0.0" and "255.255. 255.255." Another number, "127.0. 0.1" is called the "localhost;" every computer on a network refers to itself as this address. Because these numbers have special meanings, the network does not assign them to PCs; such addresses would be invalid.
Note that only a portion of the “172” and the “192” address ranges are designated for private use. The remaining addresses are considered “public,” and thus are routable on the global Internet. Use caution when setting filters to exclude these private address ranges.
The following list shows examples of valid IPv6 (Normal) addresses: 2001 : db8: 3333 : 4444 : 5555 : 6666 : 7777 : 8888. 2001 : db8 : 3333 : 4444 : CCCC : DDDD : EEEE : FFFF.
The IP address 127.0. 0.1 is a special-purpose IPv4 address and is called the localhost or loopback address. All computers use this address as their own, but it doesn't let computers communicate with other devices as a real IP address does.
According to RFC 5737:
The blocks 192.0.2.0/24 (TEST-NET-1), 198.51.100.0/24 (TEST-NET-2), and 203.0.113.0/24 (TEST-NET-3) are provided for use in documentation.
This means you can use pick an IP address from these ranges:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With