How to

resolve IP address or host name

Published: 1. February 2012 | Updated: 1. February 2012
License: Microsoft Public License (MS-PL)
Categories: Network
Tags: C# Network
Was this snippet helpful for you? YESYES / NONO

Import namespace

using System.Net;

Code

IPHostEntry entry = Dns.GetHostEntry("www.csharpdeveloping.net");

Console.WriteLine("Host name: {0}", entry.HostName);

foreach (string alias in entry.Aliases)
{
    Console.WriteLine("Alias: {0}", alias);
}

foreach (IPAddress ipAddress in entry.AddressList)
{
    Console.WriteLine("IP Address: {0}", ipAddress);
}
Send us feedback about this snippet »



Related Snippets: