如何在Windows 10中枚举mDNS服务?

问题描述 投票:0回答:1

我想在DeviceInformation.CreateWatcher应用程序中使用UWP来枚举mDNS服务:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    if (_dnsWatcher == null)
    {
        _dnsWatcher = DeviceInformation.CreateWatcher("(System.Devices.Aep.ProtocolId:=\"{4526e8c1-8aac-4153-9b16-55e86ada0e54}\")");
        _dnsWatcher.Added += DnsWatcher_Added;
        _dnsWatcher.EnumerationCompleted += DnsWatcher_EnumerationCompleted;
        _dnsWatcher.Removed += DnsWatcher_Removed;
        _dnsWatcher.Stopped += DnsWatcher_Stopped;
        _dnsWatcher.Updated += DnsWatcher_Updated;
        _dnsWatcher.Start();
    }
}

Wireshark没有显示mDNS广播,只发生了EnumerationCompleted回调。

我错过了什么吗?

uwp mdns
1个回答
0
投票

你需要添加你正在观看的内容。这是我的工作代码:

            var proto = "_gopher._tcp"; // e.g. _http._tcp
        var queryString = $"System.Devices.AepService.ProtocolId:={{{DnsSdProtocol}}} AND System.Devices.Dnssd.ServiceName:=\"{proto}\" AND System.Devices.Dnssd.Domain:=\"local\"";

        var askFor = new String[] { "System.Devices.Dnssd.HostName",
                            "System.Devices.Dnssd.ServiceName",
                            "System.Devices.Dnssd.InstanceName",
                            "System.Devices.IpAddress",
                            "System.Devices.Dnssd.PortNumber",
                            "System.Devices.Dnssd.TextAttributes",
                            };
        dw = DeviceInformation.CreateWatcher(queryString, askFor, DeviceInformationKind.AssociationEndpointService);

请注意,我的查询字符串包括用于搜索(_gopher._tcp)和dns域的协议。警告:我是DNS-SD的新手,我不知道dns域设置是有效的。

© www.soinside.com 2019 - 2024. All rights reserved.