Given an IPv4 address (needle) and an unsorted array of IPv4 addresses (haystack), how could I programmatically determine which single address in the given haystack is the closest (network-wise, NOT geographically) to the needle?
Since I don't have access to the netmask of every address, the solution should ignore netmasks and traceroute alike options.
All sorts of addresses are used, by which I mean: private, reserved, broadcast, lan and wan.
Any help in the form of theory, pseudo-code, python, php or perl is welcome.
The question Getting IP address list between two IP addresses is roughly similar, but it does quite cut it.