title: How to get IP Address from a FTP request in C#
body: <p>I have an incoming FTP request. I would like to get the IP Address of the FTP server mentioned in the incoming FTP request. I have to validate this against a list of whitelisted FTP servers.</p>
  
  <p>Any help will be well appreciated.. </p>
  
  <p>My code is as follows:</p>
  
  <pre><code>try
  {
      IPHostEntry host;
      string localIP = "?";
      host = Dns.GetHostEntry(uri);
      foreach (IPAddress ip in host.AddressList)
      {
          // we are only interested in IPV4 Addresses
          if (ip.AddressFamily == AddressFamily.InterNetwork) 
          {
              localIP = ip.ToString();
          }
      }
  
      return localIP;
  }
  catch (Exception exception)
  {
      throw;
  }
  </code></pre>