title: Get IP address through c# (in IPv4 value)
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1059526/get-ipv4-addresses-from-dns-gethostentry">Get IPv4 addresses from Dns.GetHostEntry()</a>  </p>
  </blockquote>
  
  
  
  <p>I try the following code to get my IP address, in XP, it returns the IP address V4 format,
  but when I do it in my system(windows 7), it return the ip address in v6 format.</p>
  
  <p>How do to solve this?</p>
  
  <p>Code</p>
  
  <pre><code>try
  {
        //iphostname = Dns.GetHostName();  // Resolving Host name
        IPHostEntry ipentry = Dns.GetHostEntry(hostLabel.Text);
        IPAddress[] addr = ipentry.AddressList;// Resolving IP Addresses
        for (int i = 0; i &lt; addr.Length; i++)
        {
             try
             {
                 ipLabel.Text = Convert.ToString(addr[i]) + "\r\n";
             }
             catch
             {
                 ipLabel.Text += "IP Address            | " + "\r\n";
             }
        }
  }
  catch
  {
       //richTextBox1.Text += "Hostname             | " + "\r\n";
  }
  </code></pre>