System.Net.Dns Class

Assembly: System.dll
Namespace: System.Net
Summary
Provides simple domain name resolution functionality.
C# Syntax:
public sealed class Dns
Remarks
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.

Example
The following example queries the DNS database for information on the host www.contoso.com:
IPHostEntry hostInfo = Dns.GetHostByName("www.contoso.com");
   

    
See also:
System.Net Namespace

System.Net.Dns Member List:

Public Methods
BeginGetHostByName Begins an asynchronous request for IPHostEntry information about the specified DNS host name.
BeginResolve Begins an asynchronous request to resolve a DNS host name or IP address in dotted-quad notation to an IPAddress instance.
EndGetHostByName Ends an asynchronous request for DNS information.
EndResolve Ends an asynchronous request for DNS information.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetHostByAddress Overloaded:
GetHostByAddress(IPAddress address)

Creates an IPHostEntry instance from a specified IPAddress instance.
GetHostByAddress Overloaded:
GetHostByAddress(string address)

Creates an IPHostEntry instance from an address in dotted-quad notation ("198.162.1.2").
GetHostByName Gets the DNS information for the specified DNS host name.
GetHostName Gets the host name of the local computer.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
Resolve Resolves a DNS host name or IP address in dotted-quad notation to an IPHostEntry instance.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Net.Dns Member Details

Method: BeginGetHostByName(
   string hostName,
   AsyncCallback requestCallback,
   object stateObject
)
Summary
Begins an asynchronous request for IPHostEntry information about the specified DNS host name.
C# Syntax:
public static IAsyncResult BeginGetHostByName(
   string hostName,
   AsyncCallback requestCallback,
   object stateObject
);
Parameters:

hostName

A string containing the DNS name of the host.

requestCallback

The AsyncCallback.

stateObject

The State object.

Return Value:
An IAsyncResult instance that references the asynchronous request.
Remarks
The Dns.BeginGetHostByName method starts an asynchronous request for DNS host information. The asynchronous callback method uses the Dns.EndGetHostByName method to return the actual host information.
.NET Framework Security:
DnsPermission for accessing DNS. Associated enumeration: PermissionState.Unrestricted
See also:
MSDN: asynchronousprogramming

Return to top


Method: BeginResolve(
   string hostName,
   AsyncCallback requestCallback,
   object stateObject
)
Summary
Begins an asynchronous request to resolve a DNS host name or IP address in dotted-quad notation to an IPAddress instance.
C# Syntax:
public static IAsyncResult BeginResolve(
   string hostName,
   AsyncCallback requestCallback,
   object stateObject
);
Parameters:

hostName

A string containing the DNS name of the host.

requestCallback

The AsyncCallback.

stateObject

The State object.

Return Value:
An IAsyncResult instance that references the asynchronous request.
Remarks
The Dns.BeginResolve method starts an asynchronous request for DNS host information. The asynchronous callback method uses the Dns.EndResolve method to return the actual host information.
.NET Framework Security:
DnsPermission for accessing DNS. Associated enumeration: PermissionState.Unrestricted
See also:
MSDN: asynchronousprogramming

Return to top


Method: EndGetHostByName(
   IAsyncResult asyncResult
)
Summary
Ends an asynchronous request for DNS information.
C# Syntax:
public static IPHostEntry EndGetHostByName(
   IAsyncResult asyncResult
);
Parameters:

asyncResult

The pending request for DNS information.

Return Value:
An IPHostEntry object containin DNS information about a host.
Exceptions
Exception Type Condition
ArgumentNullException asyncResult is null.
Remarks
The Dns.EndGetHostByName method completes an asynchronous request for DNS information that was started with a call to Dns.BeginGetHostByName.
See also:
MSDN: asynchronousprogramming

Return to top


Method: EndResolve(
   IAsyncResult asyncResult
)
Summary
Ends an asynchronous request for DNS information.
C# Syntax:
public static IPHostEntry EndResolve(
   IAsyncResult asyncResult
);
Parameters:

asyncResult

The pending request for DNS information.

Return Value:
An IPHostEntry object containin DNS information about a host.
Exceptions
Exception Type Condition
ArgumentNullException asyncResult is null.
Remarks
The Dns.EndResolve method completes an asynchronous request for DNS information that was started with a call to Dns.BeginResolve.
See also:
MSDN: asynchronousprogramming

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~Dns();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: GetHostByAddress(
   IPAddress address
)
Summary
Creates an IPHostEntry instance from a specified IPAddress instance.
C# Syntax:
public static IPHostEntry GetHostByAddress(
   IPAddress address
);
Parameters:

address

An IPAddress instance.

Return Value:
An IPHostEntry instance.
Exceptions
Exception Type Condition
ArgumentNullException address is null.
SocketException An error is encountered when resolving address.
.NET Framework Security:
DnsPermission for accessing DNS. Associated enumeration: PermissionState.Unrestricted

Return to top


Overloaded Method: GetHostByAddress(
   string address
)
Summary
Creates an IPHostEntry instance from an address in dotted-quad notation ("198.162.1.2").
C# Syntax:
public static IPHostEntry GetHostByAddress(
   string address
);
Parameters:

address

A string that represents an IP address in dotted-quad notation (for example, "192.168.1.2").

Return Value:
An IPHostEntry instance.
Exceptions
Exception Type Condition
ArgumentNullException address is null.
SocketException An error is encountered when resolving address.
FormatException address is not a valid IP address.
.NET Framework Security:
DnsPermission for accessing DNS. Associated enumeration: PermissionState.Unrestricted

Return to top


Method: GetHostByName(
   string hostName
)
Summary
Gets the DNS information for the specified DNS host name.
C# Syntax:
public static IPHostEntry GetHostByName(
   string hostName
);
Parameters:

hostName

A string containing the DNS name of the host.

Return Value:
An IPHostEntry object containing host information for the address specified in hostName.
Exceptions
Exception Type Condition
ArgumentNullException hostName is null.
SocketException An error is encountered resolving hostName.
Remarks
The Dns.GetHostByName method queries the Internet DNS server for host information.

For asychronous access to DNS information, use the Dns.BeginGetHostByName and Dns.EndGetHostByName methods.

.NET Framework Security:
DnsPermission for accessing DNS. Associated enumeration: PermissionState.Unrestricted

Return to top


Method: GetHostName()
Summary
Gets the host name of the local computer.
C# Syntax:
public static string GetHostName();
Return Value:
A string containing the DNS host name of the local computer.
Exceptions
Exception Type Condition
SocketException An error is encountered when resolving the local host name.
.NET Framework Security:
DnsPermission for accessing DNS. Associated enumeration: PermissionState.Unrestricted

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Resolve(
   string hostName
)
Summary
Resolves a DNS host name or IP address in dotted-quad notation to an IPHostEntry instance.
C# Syntax:
public static IPHostEntry Resolve(
   string hostName
);
Parameters:

hostName

A DNS-style host name or IP address in dotted-quad notation. (for example, "www.contoso.com " or "192.168.1.2").

Return Value:
An IPHostEntry instance containing address information about the host specified in hostName.
Exceptions
Exception Type Condition
ArgumentNullException hostName is null.
SocketException An error is encountered when resoloving hostName.
Remarks
The Dns.Resolve method queries a DNS server for the IP address associated with a host name or IP address in dotted-quad notation.

When hostName is a DNS-style host name associated with multiple IP addresses, only the first IP address that resolves to that host name is returned.

.NET Framework Security:
DnsPermission for accessing DNS. Associated enumeration: PermissionState.Unrestricted

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.