In this code snippet, I will show you how to print all the IPV4 addresses of any website using C#. For this, you have to call the static method GetHostAddressesAsync
on Dns
class. It will return an Array of IPAddress
.
Check out the following code snippet. It's self-explanatory.
class Program
{
static async Task Main(string[] args)
{
var ips = await Dns.GetHostAddressesAsync("www.microsoft.com");
foreach (var ipAddress in ips)
{
Console.WriteLine(ipAddress.MapToIPv4().ToString());
}
}
}