1 out of 3 rated this helpful Rate this topic

Dns Class

Provides simple domain name resolution functionality.

System.Object
  System.Net.Dns

Namespace:  System.Net
Assembly:  System (in System.dll)
public static class Dns

The Dns type exposes the following members.

  Name Description
Public method Static member BeginGetHostAddresses Asynchronously returns the Internet Protocol (IP) addresses for the specified host.
Public method Static member BeginGetHostByName Obsolete. Begins an asynchronous request for IPHostEntry information about the specified DNS host name.
Public method Static member BeginGetHostEntry(IPAddress, AsyncCallback, Object) Asynchronously resolves an IP address to an IPHostEntry instance.
Public method Static member BeginGetHostEntry(String, AsyncCallback, Object) Asynchronously resolves a host name or IP address to an IPHostEntry instance.
Public method Static member BeginResolve Obsolete. Begins an asynchronous request to resolve a DNS host name or IP address to an IPAddress instance.
Public method Static member EndGetHostAddresses Ends an asynchronous request for DNS information.
Public method Static member EndGetHostByName Obsolete. Ends an asynchronous request for DNS information.
Public method Static member EndGetHostEntry Ends an asynchronous request for DNS information.
Public method Static member EndResolve Obsolete. Ends an asynchronous request for DNS information.
Public method Static member GetHostAddresses Returns the Internet Protocol (IP) addresses for the specified host.
Public method Static member GetHostByAddress(IPAddress) Obsolete. Creates an IPHostEntry instance from the specified IPAddress.
Public method Static member GetHostByAddress(String) Obsolete. Creates an IPHostEntry instance from an IP address.
Public method Static member GetHostByName Obsolete. Gets the DNS information for the specified DNS host name.
Public method Static member GetHostEntry(IPAddress) Resolves an IP address to an IPHostEntry instance.
Public method Static member GetHostEntry(String) Resolves a host name or IP address to an IPHostEntry instance.
Public method Static member GetHostName Gets the host name of the local computer.
Public method Static member Resolve Obsolete. Resolves a DNS host name or IP address to an IPHostEntry instance.
Top

The Dns class is a static class that retrieves information about a specific host from the Internet Domain Name System (DNS).

The host information from the DNS query is returned in an instance of the IPHostEntry class. If the specified host has more than one entry in the DNS database, IPHostEntry contains multiple IP addresses and aliases.

The following example queries the DNS database for information on the host www.contoso.com.


IPHostEntry hostInfo = Dns.GetHostByName("www.contoso.com");
   


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(2000 characters remaining)
Community Content Add
Annotations FAQ
Need to add an overload to use a target server
This class doesn't seem to offer a method that allows you to specify a remote dns server to perform the lookup against.   As a result I'm forced to capture the input from nslookup by using the -server argument.  It would be really nice to see this added to a later version.
GetHostByName - Sample using PowerShell
<#
.SYNOPSIS
This script gets and displays basic DNS Information about a host.
.DESCRIPTION
This script just gets and displays host details returnd by GetHostByName.
.NOTES
File Name : Get-HostByName.ps1
Author : Thomas Lee - tfl@psp.co.uk
Requires : PowerShell Version 2.0
.LINK
This script posted to:
http://www.pshscripts.blogspot.com
MSDN sample posted tot:
http://msdn.microsoft.com/en-us/library/system.net.dns.aspx
.EXAMPLE
.EXAMPLE
PSH [C:\foo]: .\Get-HostByName.ps1

HostName : contoso.com
Aliases : {www.contoso.com}
AddressList : {207.46.197.32, 207.46.232.182}
#>
$hostInfo = [system.net.Dns]::GetHostByName("www.contoso.com");
$hostinfo | fl * -force