Reputation: 1344
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?
Upvotes: 3
Views: 1768
Reputation: 35449
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 %.
Upvotes: 1
Reputation: 339776
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.
Upvotes: 0