c# dns lookup from code?

Last post 11-08-2008 5:03 PM by matrixIII. 2 replies.

Sort Posts:

  • c# dns lookup from code?

    10-28-2008, 4:31 PM
    • Participant
      1,362 point Participant
    • matrixIII
    • Member since 07-23-2007, 12:32 PM
    • Posts 400

    Is there a way to do a DNS Lookup to get the DNS name given an ipaddress pragmatically, using the default dns server configured on the IIS server?

    I don't want to enable server level DNS lookup at this time. I think this would consume unnecessary time and resources since, I have to do the reverse dns for only a few ip's based on some condition in the c# code.

    Windows Server 2003 IIS 6
    .NET 2.0
    C#

    Remember to select "Mark as Answer" on the post that helped you find the solution!
  • Re: c# dns lookup from code?

    10-29-2008, 3:48 PM
    • Participant
      1,362 point Participant
    • matrixIII
    • Member since 07-23-2007, 12:32 PM
    • Posts 400

    Anyone?

    Remember to select "Mark as Answer" on the post that helped you find the solution!
  • Re: c# dns lookup from code?

    11-08-2008, 5:03 PM
    Answer
    • Participant
      1,362 point Participant
    • matrixIII
    • Member since 07-23-2007, 12:32 PM
    • Posts 400

    For anyone who is interested

     

                    try
    		{
    		LblHostName.Text = "";
    		IPAddress myIP = IPAddress.Parse(TxtInput.Text);
    
    		IPHostEntry GetIPHost = Dns.GetHostByAddress(myIP);
    		
    		LblHostName.Text = "Host Name is: " + GetIPHost.HostName;	
    		
    		}
    		catch(Exception ex)
    		{
    			LblHostName.Text = "<font color=red>Error:" + ex.Message;
    		}
    

     

    Source: http://www.aspalliance.com/cookbook/ViewChapter.aspx?Chapter=21

    Remember to select "Mark as Answer" on the post that helped you find the solution!
Page 1 of 1 (3 items)