php - Find the network distance between two IPv4 addresses (not geographic distance) -
given ipv4 address (needle) , unsorted array of ipv4 addresses (haystack), how programmatically determine single address in given haystack closest (network-wise, not geographically) needle? since don't have access netmask of every address, solution should ignore netmasks , traceroute alike options. all sorts of addresses used, mean: private, reserved, broadcast, lan , wan. any in form of theory, pseudo-code, python, php or perl welcome. the question getting ip address list between 2 ip addresses similar, quite cut it. i'm still not quite sure you're asking, based on comment @petergibson closest meant, 192.168.1.101 closer 192.168.56.1 172.30.130.66 . , 192.168.1.254 closer 192.168.1.240 192.168.2.1 you try following python code distance function: import socket def dist(a, b): def to_num(addr): # parse address string integer quads quads = map(ord, socket.inet_aton(addr)) # spread quads out return reduce(l...