We use the Dns class to get a DNS host name from an IP address, reverse lookup, or to get an IP address from a DNS host name, lookup.
The Dns class is able to communicate with the default DNS server to perform lookups and reverse lookups. The GetHostEntry method is used to retrieve IPv4 and IPv6 addresses from a hostname. The GetHostEntry method attempts a DNS reverse resolve before returning addresses back in an IPHostEntry instance. The IPHostEntry class provides a container for Internet host address information.
The Dns class has built-in support for asynchronous DNS lookups as well. We can use the BeginGetHostByName and EngGetHostByName methods.
The Dns.GetHostEntry method resolves a host name or IP address to an IPHostEntry instance. IPHostEntry has a property, HostName that holds the hostname of the site.
We can start communicating with the server. The client and server will communicate with each other via a socket. We can use the WebRequest and WebResponse classes, which are straightforward. The static method WebRequest.Create accepts a Uri object or a URI string and creates a web request basd on the URL we use. We can also use the CreateHttp method if we know it is going to be an HTTP request. The WebRequest class GetResponse method reutnrs a WebResponse object that can be used to read the data that is on the server using the GetResponseStream method that returns an IO stream.
Note that the WebRequest class does not have a public constructor.