PC Review


Reply
Thread Tools Rate Thread

How to determe if a host represents the local host?

 
 
Lars Fastrup
Guest
Posts: n/a
 
      29th Sep 2004
Hi,

given a host name, how can you i C# determine with 100% certainty if
it actually represents the local host? I am talking about DNS aliases
here.

I have tried the following, which seems to work in most cases. But it
unfortunately fails at a few customer installations:

public bool IsLocalHost(string hostName)
{
IPHostEntry localhost = Dns.GetHostByName(Environment.MachineName);
IPHostEntry hostInfo = Dns.GetHostByName(hostName);
foreach (IPAddress localhostAddress in localhost.AddressList)
{
foreach (IPAddress hostAddress in hostInfo.AddressList)
{
if (localhostAddress.Equals(hostAddress)) return true;
}
}
return false;
}

Any ideas?


Regards
Lars Fastrup
Navigo Systems
www.navigosystems.com
 
Reply With Quote
 
 
 
 
=?Utf-8?B?U3VqaXQgRCdNZWxsbw==?=
Guest
Posts: n/a
 
      29th Sep 2004
Have you tried Dns.GetHostName()? That should get the hostname of the local
computer.

Sujit D'Mello

"Lars Fastrup" wrote:

> Hi,
>
> given a host name, how can you i C# determine with 100% certainty if
> it actually represents the local host? I am talking about DNS aliases
> here.
>
> I have tried the following, which seems to work in most cases. But it
> unfortunately fails at a few customer installations:
>
> public bool IsLocalHost(string hostName)
> {
> IPHostEntry localhost = Dns.GetHostByName(Environment.MachineName);
> IPHostEntry hostInfo = Dns.GetHostByName(hostName);
> foreach (IPAddress localhostAddress in localhost.AddressList)
> {
> foreach (IPAddress hostAddress in hostInfo.AddressList)
> {
> if (localhostAddress.Equals(hostAddress)) return true;
> }
> }
> return false;
> }
>
> Any ideas?
>
>
> Regards
> Lars Fastrup
> Navigo Systems
> www.navigosystems.com
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem timeout with host-to-host IPSEC in transport mode =?Utf-8?B?UGVyc29UaGFsZXM=?= Windows XP Security 5 25th Oct 2007 08:03 AM
Win 2000 - Unable to Resolve Host Domain Names From Host Web Server clixy1@hotmail.com Microsoft Windows 2000 DNS 1 14th Jul 2007 05:26 AM
How to scan IIS host or Sql Server host in local network? =?Utf-8?B?Sm9uYXRoYW4gTGVl?= Microsoft C# .NET 1 11th Apr 2004 05:15 AM
local host Geddy Lee Windows XP Basics 1 11th Mar 2004 11:01 PM
Virtual PC host-guest networking when host not connected to a network? Dominiek Cottem Windows XP Networking 1 19th Nov 2003 09:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:43 PM.