Skip to content

Приказ IPv6 адреса мрежних интерфејса (C#)

using System;
using System.Net.NetworkInformation;
using System.Net.Sockets;

namespace IPadrese
{
    internal class Program
    {
        static void Main(string[] args)
        {
            NetworkInterface[] interfejsi = NetworkInterface.GetAllNetworkInterfaces();
            Console.WriteLine("Broj mrežnih adaptera: {0}", interfejsi.Length);
            foreach (NetworkInterface interfejs in interfejsi)
            {
                Console.WriteLine();
                Console.WriteLine(interfejs.Description);
                Console.WriteLine("Tip adaptera : {0}", interfejs.NetworkInterfaceType);
                Console.Write("IPv6 adresa  : ");
                foreach (UnicastIPAddressInformation ipAdresa in interfejs.GetIPProperties().UnicastAddresses)
                    if (ipAdresa.Address.AddressFamily == AddressFamily.InterNetworkV6)
                        Console.WriteLine(ipAdresa.Address);
                Console.WriteLine();
            }
        }
    }
}

Тест пример

Broj mreznih adaptera: 2

Realtek PCIe GBE Family Controller
Tip adaptera : Ethernet
IPv6 adresa  : fe80::f511:aeb5:50fc:7f59%8


Software Loopback Interface 1
Tip adaptera : Loopback
IPv6 adresa  : ::1