C# Program To Print All the IP Addresses of the Given Website

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());
            }

           
		}
	} 

Post a Comment

Please do not post any spam link in the comment box😊

Previous Post Next Post

Blog ads

CodeGuru