tags:

views:

39

answers:

2

Hi,

I just came across an issue, where I had to check if a path points into a windows share. Part of this problem is to check if host A is the same as host B. Where host A and host B can be one of the following {IPv4-Address, IPv6-Address, Hostname, FQDN}. As I do not need to be exact it's enough to resolve and compare the IP-Addresses in my case.

But is there, theoretically, a method to check if the hosts are the same?

A: 

Pass the two addresses into the getaddrinfo() function, and compare the resulting lists for any matches.

Unlike gethostbyname(), this function will happily parse IPv6 literals, and will also return any relevant A or AAAA records associated with a host name.

Alnitak
I thing with this method you will get false negatives. Consider machine A has two IP-Addresses, let's say 192.168.1.1 and 192.168.2.1. The addresses don't match, but the host is the same. BTW: Same problem with MAC-Addresses.
Michael Stoll
Yes, of course you will. There's no end of ways to defeat this sort of logic. It can tell you that two hosts _are_ the same - it cannot prove that they _are not_.
Alnitak
+1  A: 

No, there is no general method to see if two identifiers (names or addresses) go to the same host. One example: 192.0.2.1 and 2001:db8::bad:dcaf. Are they the same? (Answer: cannot tell)

There is no general concept of host identity in the Internet. Some protocols have such a concept, for instance SSH (connect to the hosts, see if the fingerprints match) or HIP (test the keys) but you depend on this protocol being activated for these specific machines.

Some heuristics may help (fingerprinting the machine, for instance) but it will be far from 100 %.

bortzmeyer