Use AsyncCallback event to resolve a host name : DNS « Network « C# / CSharp Tutorial






using System;
using System.Drawing;
using System.Net;
using System.Text;
using System.Windows.Forms;

class MainClass
{
   private static void Resolved(IAsyncResult ar)
   {
      string buffer;

      IPHostEntry iphe = Dns.EndResolve(ar);

      buffer = "Host name: " + iphe.HostName;
      Console.WriteLine(buffer);

      foreach(string alias in iphe.Aliases)
      {
         buffer = "Alias: " + alias;
         Console.WriteLine(buffer);
      }
      foreach(IPAddress addrs in iphe.AddressList)
      {
         buffer = "Address: " + addrs.ToString();
         Console.WriteLine(buffer);
      }
   }

   public static void Main()
   {
      AsyncCallback OnResolved;

      OnResolved = new AsyncCallback(Resolved);

      string addr = "www.java2s.com";
      Object state = new Object();

      Dns.BeginResolve(addr, OnResolved, state);
   }
}








33.2.DNS
33.2.1.DNS Name and Its IPHostEntry
33.2.2.Get DNS host name
33.2.3.Get IP address from host name
33.2.4.Get Host by IP address
33.2.5.Get IPAddress from IPHostEntry
33.2.6.Get IPHostEntry by host name
33.2.7.Resolve a Host name
33.2.8.Get Address List from HostEntry
33.2.9.Use AsyncCallback event to resolve a host name
33.2.10.Dns Lookup