0

In my c++ application I want to detect if two host identifiers (name or/and IP) are pointing to same host (including local and net IPs). For example "google.com" and "209.85.148.105" are same, "127.0.0.1" is possibly same with any host identifier.

In other words there is a function:

bool test_host(std::string const & host, std::set<std::string, case_insensitive_comparator> const & host_ids)
{
    return host_ids.find(host) != host_ids.end();
}

But I don't know how to generate host_ids. So how should I do?

P.S. My application is cross-platform and I would like to get such an answer which will work for both unix and windows.

Mihran Hovsepyan
  • 10,810
  • 14
  • 61
  • 111
  • Looks like a duplicate to this question: http://stackoverflow.com/questions/2674314/get-local-ip-address-using-boost-asio – littleadv Jun 21 '11 at 07:36
  • 3
    As stated it is probably impossible, you can bind more than one IP address to the same network port (or use more than one network card) and there is no way to know that those unique addresses are in fact the same host from outside. With NAT, two seemingly unrelated addresses might refer to the same server (a common example is private address at home, the address of your router), or conversely a router might forward traffic from different ports of the same address to different internal IPs. – David Rodríguez - dribeas Jun 21 '11 at 07:37
  • 1
    And you're not even mentioning IPV6. This is _not primarily_ a programming question. It is a network engineering question (heavy on ARP, DNS, routing) – sehe Jun 21 '11 at 08:52
  • Even if you consider nmapping them to try to use that as a fingerprint, a single host may also run virtual machines with virtual hosts. I'm going for "impossible" as asked. – dascandy Jul 12 '11 at 06:22

0 Answers0