;

How to Get the IPv6 IP Address of the Local Computer in C#


Tutorialsrack 31/07/2020 C#

In this article, you will learn how to get the IPv6 IP Address of the local computer in C#.

Here is the source code of the program to get the IPv6 IP Address of the Local Computer in C#.

How to Get the IPv6 IP Address of the Local Computer in C#
using System;
using System.Net;

namespace Tutorialsrack
{
    class Program
    {
        /* How to Get the IPv6 IP Address of the Local Computer in C# */
        static void Main(string[] args)
        {
            get_IPv6_Local_IP();

            //Hit ENTER to exit the program
            Console.ReadKey();
        }

        public static void get_IPv6_Local_IP()
        {
            try
            {
                string strHostName = System.Net.Dns.GetHostName(); ;
                IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
                IPAddress[] addr = ipEntry.AddressList;
                Console.WriteLine("Local Ipv4 IP Address: "+addr[addr.Length - 1].ToString());
                if (addr[0].AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
                {
                    Console.WriteLine("Local Ipv6 IP Address: "+addr[0].ToString()); //ipv6
                }
            }
            catch (Exception) { }
        }

    }
}

I hope this article will help you to understand how to get the IPv6 IP Address of the local computer in C#.

Share your valuable feedback, please post your comment at the bottom of this article. Thank you!


Related Posts



Comments

Recent Posts
Tags