none
two ip addresses on same adapter RRS feed

  • Question

  • Hello:

    I manage to get ip in  C# but the problem i have 2 ip addresses 

    when i try to get the IP address I get the second one not the first

    Tuesday, September 4, 2018 11:01 AM

All replies

  • Well, just a guess, your invisible code is not correct..
    Tuesday, September 4, 2018 12:18 PM
  • Hello:

    I manage to get ip in  C# but the problem i have 2 ip addresses 

    when i try to get the IP address I get the second one not the first

    Hi,

    How did you get it?

    To get local IP address:

    public static string GetLocalIPAddress()
    {
        var host = Dns.GetHostEntry(Dns.GetHostName());
        foreach (var ip in host.AddressList)
        {
            if (ip.AddressFamily == AddressFamily.InterNetwork)
            {
                return ip.ToString();
            }
        }
        throw new Exception("No network adapters with an IPv4 address in the system!");
    }

    Refer: Get local IP address

    Also the following thread may help you:

    C# get local IP but IPAddress.AddressFamily has many IPs

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, September 5, 2018 6:18 AM
  • I managed to get the IPs for all my local adapters but one of the I use in it 2 ips and put it in textbox 

    when i search i got both of them but keep putting second one not the first

    Wednesday, September 5, 2018 7:24 PM
  • Hi,

    Sorry for the late reply.

    How did you get the 2 IPs in your code?

    What do you mean that keep putting second one not the first?

    Hope you can provide more details for this issue.

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, September 19, 2018 6:15 AM