2011-10-18 188 views
1

我在使用UDP广播消息构建设备发现系统。我开始使用UdpClientIPAddress.Broadcast查找所有本地网络广播地址

此解决方案适用于本地计算机上的客户端,而不是本地网络上的其他客户端。

通过this question,我发现Win 7阻止广播消息。当我手动输入本地网络广播地址时,它的效果很好。现在我想写一些代码遍历所有本地网络适配器(如NetworkInterfaces.GetAllNetworkInterfaces()),并找到每个适配器连接到的网络的本地网络广播地址(如果有的话)。

这是否有意义?最好的办法是ping与Win 7,IPv6,IPv4等兼容的本地子网。换句话说,通用兼容。

谢谢!

回答

4

好的,像...一样?

foreach (NetworkInterface Interface in NetworkInterface.GetAllNetworkInterfaces()) 
     { 
      if (Interface.SupportsMulticast) 
      { 
       IPInterfaceProperties IPProperties = Interface.GetIPProperties(); 
       foreach (IPAddressInformation address in IPProperties.MulticastAddresses) 
       { 
        Console.WriteLine(address.Address); 
       } 
      } 
     } 
    } 
+0

是否可以使用'NetworkInterface'类而不是WMI来做这种事? –