title: C# - How to get IP Address when connected to (RAS) VPN
body: <p>Good afternoon,</p>
  
  <p>Can anyone give any examples of how to obtain the IP Address of the local machine when it's connected to a remote windows domain network via VPN (RAS)? i.e. I need the VPN address and not the remote users local network address.</p>
  
  <p>For example, my Server Side Windows Service communicates with my client side application and needs to create a log of all connected users and their IP Addresses.</p>
  
  <p>This solution is easy enough when using a computer on the local network, but I wondered how I can go about getting the IP addresses of the users who are connected to the server via VPN. Please note that the IP address <strong>get</strong> method will be executed client side and sent to the server.</p>
  
  <p><strong>Here's my current code that works only when locally connected to the domain network:</strong></p>
  
  <pre><code>public static string GetLocalIPv4()
  {
      string ipv4Address = String.Empty;
  
      foreach (IPAddress currrentIPAddress in Dns.GetHostAddresses(Dns.GetHostName()))
      {
          if (currrentIPAddress.AddressFamily.ToString() == System.Net.Sockets.AddressFamily.InterNetwork.ToString())
          {
              ipv4Address = currrentIPAddress.ToString();
              break;
          }
      }
  
      return ipv4Address;
  }
  </code></pre>
  
  <p>Our internal network is controlled by Windows SBS and uses a domain such as mycompany.local. </p>
  
  <p>Thank you very much for your time and I look forward to reading your responses.</p>
  
  <p>Rob</p>