title: How to include ipv6 addresses with (or without) zone indexes in uri for .net remoting?
body: <p>This application publishes its own address for other systems to connect to using .net remoting. It gets all the addresses of the computer with something like:</p>
  <pre><code>IPAddress[] IPList = Dns.GetHostEntry(Environment.MachineName).AddressList;
  string ipAddress = IPList[ipIndex].ToString();
  if(ipAddress.contains(&quot;:&quot;))
  {
    // ip6 address
    url = &quot;tcp://[&quot; + ipAddress + &quot;]:&quot; + port + &quot;/&quot; + name;
  }
  else
  {
    url = &quot;tcp://&quot; + ipAddress + &quot;:&quot; + port + &quot;/&quot; + name;
  }
  </code></pre>
  <p>I added the square brackets in case it was getting confused by the colons as per <a href="https://www.rfc-editor.org/rfc/rfc2732" rel="nofollow noreferrer">this</a> rfc. I think the problem is zone indexes - <code>ToString()</code> returns <code>fe80::a8e8:2b42:3c07:c04a%10</code> - Note the <code>%10</code> zone index. Can I put the zone index into a url? According to <a href="http://en.wikipedia.org/wiki/IPv6_address#Link-local_addresses_and_zone_indices" rel="nofollow noreferrer">this</a> wikipedia page they cause problems? Do I need the zone index? Is there some better way to assemble a uri from an IP address?</p>
  <p>edit:</p>
  <p>As per the answer to find the valid addresses I changed the code to ignore link local addresses, loopback and multicast addresses - this excludes these in windows7 eg.</p>
  <pre><code>IPList[ipIndex].IsIPv6LinkLocal || IPList[ipIndex].IsIPv6Multicast || IPAddress.IsLoopback(IPList[ipIndex])
  </code></pre>
  <p>I am now assuming that if someone uses this software with an actual ipv6 address windows will not report the address as having a zone index or else the url I build will break. I was hoping for an existing .net url building class that could take an IPAddress, port, etc as input or even better for some way to connect a remoting client to an IPAddress class instead of a string url as is required in Activator.GetObject but this will do for now.</p>