title: Problem Converting ipv6 to ipv4
body: <p>I have some code in an asp.net app that needsto get the ipv4 address of the client computer (the users are all on our own network). Recently we upgraded the server the app runs on to windows 2008 server. Now the Request.UserHostAddress code returns the ipv4 when the client is on an older OS and ipv6 when they are on a newer OS (Vista and higher). So the feature that relys on this works for some clients and not others. </p>
  
  <p>I added code that is supposed to convert from ipv6 to ipv4 to try to fix this problem. It's from this online tutorial: <a href="https://web.archive.org/web/20211020102847/https://www.4guysfromrolla.com/articles/071807-1.aspx" rel="noreferrer">https://web.archive.org/web/20211020102847/https://www.4guysfromrolla.com/articles/071807-1.aspx</a> .I'm using dsn.GetHostAddress and then looping through the IPs returned looking for one that is "InterNetwork"</p>
  
  <pre><code>foreach (IPAddress IPA in Dns.GetHostAddresses(HttpContext.Current.Request.UserHostAddress))
  {
      if (IPA.AddressFamily.ToString() == "InterNetwork")
      {
          IP4Address = IPA.ToString();
          break;
      }
  }
  
  if (IP4Address != String.Empty)
  {
      return IP4Address;
  }
  
  
  foreach (IPAddress IPA in Dns.GetHostAddresses(Dns.GetHostName()))
  {
      if (IPA.AddressFamily.ToString() == "InterNetwork")
      {
          IP4Address = IPA.ToString();
          break;
      }
  }
  
  return IP4Address;
  </code></pre>
  
  <p>The problem is that this isn't working for me. The clients connecting from ipv4 continue to return the correct ipv4 IP of the client computer, but the clients connecting from Vista and Windows 7 it is returning the ipv4 IP of the <em>SERVER</em> machine not the client computer. </p>