[SOLVED] How to find the IP Address I'm using (Ethernet vs. Wi-Fi)?

Stout 281 Reputation points

Hi. I need to find the IPv4 address of my PC. When I run IPConfig I get two IP Addresses, one for the "Ethernet adapter vEthernet (Default Switch)" and one for the "Wireless LAN adapter Wi-Fi."

My laptop has no ethernet switch, and is currently connected to the Wi-Fi network. The following API returns both ethernet and wi-fi IP addresses. How can I determine which one is what I am truly connected to?


IPAddress[] ipv4Addresses = Array.FindAll(Dns.GetHostEntry(string.Empty).AddressList,
                                               a => a.AddressFamily == AddressFamily.InterNetwork);
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
8,156 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 71,606 Reputation points

    You can use Network List Manager

    // Add reference to : Network List Manager 1.0 Type Library
    // Add : using NETWORKLIST;

    A test :

    NetworkListManager nlm = new NetworkListManager();
    IEnumNetworks networks = nlm.GetNetworks(NLM_ENUM_NETWORK.NLM_ENUM_NETWORK_CONNECTED);
    foreach (INetwork netw in networks)
        Console.WriteLine("Connected Network : " + netw.GetName() + " - Internet : " + netw.IsConnectedToInternet.ToString());
        foreach (INetworkConnection nc in netw.GetNetworkConnections())
            string sIP = GetIPFromAdapter("{" + nc.GetAdapterId().ToString() + "}");
            if (sIP != null)

    Utility function (remove static if not needed) :

    static public string GetIPFromAdapter(string sAdapterID)
        string sRet = null;
        foreach (System.Net.NetworkInformation.NetworkInterface ni in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces())
            if (ni.Id.Equals(sAdapterID, StringComparison.CurrentCultureIgnoreCase))                    
                foreach (System.Net.NetworkInformation.UnicastIPAddressInformation ip in ni.GetIPProperties().UnicastAddresses)
                    if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                        sRet = ip.Address.ToString();
        return sRet;
    1 person found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Michael Taylor 41,551 Reputation points

    I think you're asking the wrong question. You do have 2 IP addresses. One is your wifi adapter. The other is coming from the virtual network and that tells me you probably have Hyper-V turned on or VPN software installed. Both of these route your physical ethernet through a virtual switch. Which one you use (which could be both by the way) is dependent upon a variety of things but ultimately is controlled by the bindings that Windows is using. For example if you are connecting to a VM that you are hosting locally it is likely going through the virtual ethernet that is configured and the IP address is coming from either Hyper-V or perhaps passthrough to your actual DHCP server, depending upon how it is configured. But if you're using a browser then it is likely running through your wifi adapter.

    So "which one am I truly connected to" depends. What do you intend to do with this information? If you want to use it to connect to an Internet resource then the better question might be "which one has internet access". Unfortunately that is difficult to test outside of just pinging. This SO post has some suggestions but none of them are reliable or full proof.

    1 person found this answer helpful.

  2. cthivierge 3,981 Reputation points

    you could run this PS command

    Get-NetIPAddress | ft IPAddress,InterfaceAlias

    It will list you all the IP address and the Interface Alias...

    something like this.. (You may have more entry actually)

    IPAddress InterfaceAlias Ethernet Wi-Fi Loopback Pseudo-Interface 1

    The look for "Wi-Fi" or something like that...

    Ethernet is the physical network adapter.

    Normally, a valid IP address for a network should never start with 169.254.x.x


    1 person found this answer helpful.

  3. BurrWalnut 11 Reputation points

    Open a Run window (Windows Logo key+R), type cmd /k ipconfig (note the two spaces), press Enter and the internal IP Address of the computer (usually beginning with 192.168) will be displayed.

    Your external IP Address can be found here http://whatismyipaddress.com/