How can o开发者_Python百科ne 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.
Have a look at this stackoverflow-qestion, especially Eric Rosenberger's answer: Method to determine if path string is local or remote machine
精彩评论