Using DNS
The networking types in the base class library also support normal and reverse Domain Name System (DNS) resolution. Here’s an example using these types:
// DNSLookup.cs // Run DNSLookup.exe <servername> to determine IP addresses using System; using System.Net; class DNSLookup { static void Main(string[] args) { IPHostEntry he = Dns.GetHostByName(args[0]); IPAddress[] addrs = he.AddressList; foreach (IPAddress addr in addrs) Console.WriteLine(addr); } }
Get C# in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.