none
Get All IP addresses for one Network Card for Example "Ethernet1" RRS feed

  • Question

  • Hello:

    I have a multi Private IP addresses for one Network Card and I have other Network Cards,

    I want to get The IP addresses for one Network Card not all Network Cards. 

    Thanks in advance

    Language is C#



    • Edited by AbduAllah10 Thursday, December 13, 2018 7:48 PM Explain Programming Language
    Thursday, December 13, 2018 2:08 PM

Answers

  • What are you using to get the network information now (e.g. WMI, NetworkInformation, etc)? For NetworkInformation try this code to see if it gives you what you want.

    var ifcs = NetworkInterface.GetAllNetworkInterfaces();
    foreach (var ifc in ifcs)
    {
        Console.WriteLine($"{ifc.Name}");
    
        var props = ifc.GetIPProperties();
        foreach (var ip in props.UnicastAddresses)
        {
            Console.WriteLine($"\t{ip.Address}");
        };
    };


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by AbduAllah10 Thursday, December 13, 2018 7:54 PM
    Thursday, December 13, 2018 6:32 PM
    Moderator

All replies

  • What are you using to get the network information now (e.g. WMI, NetworkInformation, etc)? For NetworkInformation try this code to see if it gives you what you want.

    var ifcs = NetworkInterface.GetAllNetworkInterfaces();
    foreach (var ifc in ifcs)
    {
        Console.WriteLine($"{ifc.Name}");
    
        var props = ifc.GetIPProperties();
        foreach (var ip in props.UnicastAddresses)
        {
            Console.WriteLine($"\t{ip.Address}");
        };
    };


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by AbduAllah10 Thursday, December 13, 2018 7:54 PM
    Thursday, December 13, 2018 6:32 PM
    Moderator
  • Hello 

    Thanks for the answer.

    Thursday, December 13, 2018 8:44 PM