title: Get the IP address of a machine connected to/in a VPN network
body: <p>I need to know the IP address of a machine connected to a VPN. I have used the following algorithm to do so:</p>
  
  <pre><code>if (NetworkInterface.GetIsNetworkAvailable()) { // First check if any connections are present
  NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
  bool vpnExists=false;
  string ipAddr="?";
  foreach (NetworkInterface Interface in interfaces)
  { // Loop through all interfaces present
      if (Interface.OperationalStatus == OperationalStatus.Up)
      { // consider only if an interface is currently active
          if (Interface.NetworkInterfaceType == NetworkInterfaceType.Tunnel) // refering to vpn
          { // vpn found              
              vpnExists=true;
              foreach (UnicastIPAddressInformation ip in Interface.GetIPProperties().UnicastAddresses) { 
                  // Program control reaches here without any problem
                  if (ip.Address.AddressFamily==AddressFamily.InterNetwork) { // this block does not execute as expected
                      ipAddr=ip.Address.ToString();
                  }
              }
          }
          else
          { // vpn not found
              continue; // Goto another interface
          }
      }
    }             
  }
  /*
  Final state of variables:
     vpnExists: true
     ipAddr: "?"
  */
  </code></pre>
  
  <p>The code functions perfectly till the VPN checking part (for all networks I've tried on) but does not display the IP address after the detection of VPN. I don't understand why the statement <code>(ip.Address.AddressFamily==AddressFamily.InterNetwork)</code> returns false as I believe that it is the correct way to get IP addresses.</p>
  
  <p>Can anyone please point out why is this happening? And an in-depth explanation would also be helpful.</p>
  
  <p>Thanks in advance.</p>
  
  <p>UPDATE:
  This issue has been solved by mapping the IP address manually. Anyways, thanks to everyone who took interest and helped to solve.   </p>