How to check if two hosts match

I just ran into a problem where I had to check if the path points to a Windows share. Part of this problem is to check if host A matches host B. Where host A and host B can be one of the following {IPv4-Address, IPv6-Address, Hostname, FQDN}. Since I do not need to be precise, it is enough to allow and compare IP addresses in my case.

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

+3
source share
2 answers

No, there is no general method to see if two identifiers (names or addresses) go to the same host. One example: 192.0.2.1and 2001:db8::bad:dcaf. They are the same? (Answer: I can not say)

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

Some heuristics can help (a fingerprint on a machine, for example), but it will be far from 100%.

+2
source

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

gethostbyname(), IPv6 A AAAA, .

0

Source: https://habr.com/ru/post/1747046/


All Articles