本文介绍了如何包括与(或无)的URI的.NET远程IPv6地址区指标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该应用程序将发布它自己的地址,其他系统连接到使用.NET远程处理。进入计算机的所有地址的东西,如:

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:

IPAddress[] IPList = Dns.GetHostEntry(Environment.MachineName).AddressList;
string ipAddress = IPList[ipIndex].ToString();
if(ipAddress.contains(":"))
{
  // ip6 address
  url = "tcp://[" + ipAddress + "]:" + port + "/" + name;
}
else
{
  url = "tcp://" + ipAddress + ":" + port + "/" + name;
}

我加方括号的情况下,它是越来越糊涂了冒号按照 RFC 。我认为这个问题是区域指数 - 的ToString()返回 FE80 :: a8e8:2b42:3c07:c04a%10 - 注意 10%区域指数。我可以把区指数为URL?据的维基百科页面,他们会出现问题?我是否需要区域指数?有一些更好的方法来从一个IP地址组成一个URI?

I added the square brackets in case it was getting confused by the colons as per this rfc. I think the problem is zone indexes - ToString() returns fe80::a8e8:2b42:3c07:c04a%10 - Note the %10 zone index. Can I put the zone index into a url? According to this wikipedia page they cause problems? Do I need the zone index? Is there some better way to assemble a uri from an IP address?

编辑:

根据答案找我换了code忽略链路本地地址,环回和多播地址的有效地址 - 这不包括这些在Windows7如

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.

IPList[ipIndex].IsIPv6LinkLocal || IPList[ipIndex].IsIPv6Multicast || IPAddress.IsLoopback(IPList[ipIndex])

我现在假设,如果有人使用该软件的实际IPv6地址的窗口将不报告的地址为具有区指数否则URL我建立将打破。我希望为现有.NET URL建筑类,可以采取一个ip地址,端口等的输入,甚至对一些更好的方式到远程客户端连接到一个ip地址类,而不是一个字符串的URL如需要Activator.GetObject但这将做吧。

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.

推荐答案

该区域指标并不意味着任何其他系统。 (您的区域指数10可能是别人的区域指数25,为eth0,EN0,等等,这取决于恰好是在使用特定的网络的网络接口,以及平台)。另外,因为它们的,(你可以告诉,因为他们开始与 FE80 :: ),他们只可用,如果他们被发布到其它机器的本地局域网上,反正。

The zone indexes won't mean anything to other systems. (Your zone index 10 might be someone else's zone index 25, eth0, en0, etc, depending on the network interface that happens to be in use for that particular network, and the platform.) Plus, since they are link-local addresses, (you can tell because they start with fe80::) they are only usable if they are being advertised to other machines on the local LAN, anyway.

我建议你不做广告IPv6链路本地地址。如果你必须通告他们,看看是否有一种方法将它们只发布到特定的接口和离开关区指数。其他系统需要知道链路本地地址是从,他们从收到相同的接口只可用。

I would suggest you not advertise IPv6 link-local addresses. If you must advertise them, see if there is a way to advertise them only to specific interfaces and leave off the zone index. Other systems would need to know that link-local addresses are only usable from the same interface they were received from.

远越好将是IPv6路由器添加到您的网络,并且只使用全球单播地址

Far better would be to add an IPv6 router to your network, and use only global unicast addresses.

这篇关于如何包括与(或无)的URI的.NET远程IPv6地址区指标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 15:53