Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2004

Tip: Looking for answers? Try searching our database.

How to determe if a host represents the local host?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lars Fastrup - 29 Sep 2004 13:23 GMT
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
Sujit D'Mello - 29 Sep 2004 19:33 GMT
Have you tried Dns.GetHostName()? That should get the hostname of the local
computer.

Sujit D'Mello

> Hi,
>
[quoted text clipped - 25 lines]
> Navigo Systems
> www.navigosystems.com

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.