General answer: no, if you have a machine with two network cards (for example), there is no sure way to find out that it comes from the same computer, since these are really two different network elements.
However, you can handle some special cases, such as localhost versus 127.0.0.1, which you mentioned.
When you get multiple IP addresses from a DNS query, this usually means that the machines DO NOT match, since this method is usually used to balance the load between different machines.
There were many hacking methods in the past to detect if 2 ips are the same machines, in some cases you can get the internal time of the machine or open the ports in serial order, you can also use this. But I strongly advise you not to go this route. It is probably best to achieve your goal without performing this check (for example, if you have a web application, you can easily use cookies for this). Again, more context is needed to help.
source share