Chapter 14. Web
The World Wide Web has worked its way into every nook and cranny of what most .NET developers encounter when building their solutions today. Web services are on the rise, and ASP.NET is one of the main players in the web application space. Because of the general needs to deal with HTML and TCP/IP name resolution and because uniform resource indicators and uniform resource locators are being used for more and more purposes, developers need tools to help them concentrate on building the best web-interactive applications they can. This chapter is dedicated to taking care of some of the grunge that comes along with programming when the Web is involved. This is not an ASP.NET tutorial chapter but rather covers some functionality that developers can use in both ASP.NET and other C#-based applications. For more on ASP.NET, see ASP.NET Cookbook and Programming ASP.NET, Second Edition (both from O'Reilly).
14.1. Converting an IP Address to a Hostname
You have an IP address that you need to resolve into a hostname.
Dns.GetHostEntry method to get the hostname for an IP address. In the following code, an IP address is resolved, and the hostname is accessible from the
HostName property of the
using System; using System.Net; IPHostEntry iphost = Dns.GetHostEntry("127.0.0.1"); string hostName = iphost.HostName; // Print out name. Console.WriteLine(hostName);
System.Net.Dns class is provided for simple DNS resolution ...