0

How can one check that an absolute Uri refers the local machine?

Currently I am using this simple procedure:

var isLocalMachine = uri.IsLoopback || string.Equals(uri.HostName, Environment.MachineName, StringComparison.OrdinalIgnoreCase);

But this is not good enough, because:

  • the optional domain name is left unattended.
  • the same machine may have several different DNS names
  • the host name may be an IP address, which is not handled at all

If it is possible, I would like to have a procedure, which does not generate any network queries.

Thanks.

mark
  • 59,016
  • 79
  • 296
  • 580

1 Answers1

0

Have a look at this stackoverflow-qestion, especially Eric Rosenberger's answer: Method to determine if path string is local or remote machine

Community
  • 1
  • 1
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939