title: How to Get Client IP Address using Asp.Net C# - When our Project is Hosted in IIS
body: <p>i am working in asp.net c#, in that i need to get client IP Address to display the client IP.
  i am hosting my project in IIS 7, using the static ip i can connect my application..</p>
  
  <p>i have to fetch the client IP using the following code. but i can't get correct ip address..</p>
  
  <p>every time i get this ip 192.168.1.18..</p>
  
  <p>i use the following code</p>
  
  <pre><code>private void GetIP()
      {
         string userip = Request.UserHostAddress;
          if (Request.UserHostAddress != null)
          {
              Int64 macinfo = new Int64();
              string macsrc = macinfo.ToString("X");
              if (macsrc == "0")
              {
                  if (userip == "127.0.0.1")
                  {
                      //ScriptManager.RegisterStartupScript(this, GetType(), "Message", "alert('Visited Localhost')", true);
                      lblIPAddress.Text = userip;
                  }
                  else
                  {
                      lblIPAddress.Text = userip;
                  }
              }
          }            
      }
  </code></pre>
  
  <p>i am also using the following code also but it showing the hosted ip address like 192.168.1.5, where i am hosted my project in server..</p>
  
  <pre><code>public static string GetLocalIPAddress()
      {
          var host = Dns.GetHostEntry(Dns.GetHostName());
          foreach (var ip in host.AddressList)
          {
              //if (ip.AddressFamily == AddressFamily.InterNetwork)
              if (ip.AddressFamily != AddressFamily.InterNetworkV6)
              {
                  return ip.ToString();
              }
          }
          throw new Exception("Local IP Address Not Found!");
      }
  </code></pre>
  
  <p>i need the correct client ip address, any one help</p>