title: How to get the public IP address of a user in C#
body: <p>I want the public IP address of the client who is using my website.
  The code below is showing the local IP in the LAN, but I want the public IP of the client.</p>
  
  <pre><code>//get mac address
  NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
  String sMacAddress = string.Empty;
  foreach (NetworkInterface adapter in nics)
  {
      if (sMacAddress == String.Empty)// only return MAC Address from first card  
      {
          IPInterfaceProperties properties = adapter.GetIPProperties();
          sMacAddress = adapter.GetPhysicalAddress().ToString();
      }
  }
  // To Get IP Address
  
  
  string IPHost = Dns.GetHostName();
  string IP = Dns.GetHostByName(IPHost).AddressList[0].ToString();
  </code></pre>
  
  <p>Output: </p>
  
  <blockquote>
    <p>Ip Address : 192.168.1.7</p>
  </blockquote>
  
  <p>Please help me to get the public IP address.</p>