Dns

Dns CF 1.0, ECMA 1.0

System.Net (system.dll) sealed class

This type offers up a collection of static methods for resolving DNS (Domain Name Service) operations. Because raw IP addresses (such as 192.168.0.1) can be difficult for humans to remember, DNS servers take human-friendly names (such as "www.oreilly.com") and in turn translate them into IP addresses and/or back again. This ability can be useful in a variety of scenarios, including the simple logging of clients who have visited a web site recently. (Note that this is not a secure way of tracking usageeven a simple attacker can spoof the return address of an IP packet, so don't rely on this mechanism for any kind of security validation or audit trail.)

The GetHostByName( ) method takes a hostname (such as "www.oreilly.com") and returns the corresponding IPHostEntry instance; this IPHostEntry instance is used later in several of the System.Net and System.Net.Sockets types. This method (along with the paired method Resolve( ) ) can be invoked asynchronously using the BeginGetHostByName( ) or BeginResolve( ) methods. Like all async methods in the .NET Framework, they take two additional parameters: an AsyncCallback object, and a generic object parameter that is passed to the AsyncCallback when the call completes.

At the surface, there would appear to be no difference between calling Resolve( ) or GetHostByName( ) ; in fact, the Resolve( ) method calls into GetHostByName( ) after doing a small amount of preprocessing to check if the string passed is either a standard host name ("www.oreilly.com") or a dotted -quad IP address ("192.168.0.1"); GetHostByName( ) requires a hostname. (For those familiar with the Berkeley sockets API, the GetHostByName( ) method is a wrapper around the native BSD gethostbyname function.)

 public sealed class  Dns  {  // Public Static Methods  public static IAsyncResult  BeginGetHostByName  (string   hostName   , AsyncCallback   requestCallback   ,          object   stateObject   );    public static IAsyncResult  BeginResolve  (string   hostName   , AsyncCallback   requestCallback   ,          object   stateObject   );    public static IPHostEntry  EndGetHostByName  (IAsyncResult   asyncResult   );    public static IPHostEntry  EndResolve  (IAsyncResult   asyncResult   );    public static IPHostEntry  GetHostByAddress  (IPAddress   address   );    public static IPHostEntry  GetHostByAddress  (string   address   );    public static IPHostEntry  GetHostByName  (string   hostName   );    public static string  GetHostName  ( );    public static IPHostEntry  Resolve  (string   hostName   ); } 


C# in a Nutshell
C # in a Nutshell, Second Edition
ISBN: 0596005261
EAN: 2147483647
Year: 2005
Pages: 963

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net