1、创建一个DNS服务:可以使用MulticastService
类来创建一个DNS服务实例,并为其指定主机名和端口号。
var service = new MulticastService("mydns.local", IPAddress.Parse("224.0.0.251"), 5353);
2、添加DNS解析记录:可以使用ServiceAnnouncement
类来添加DNS解析记录,并将其绑定到DNS服务实例上。
var announcement = new ServiceAnnouncement(); announcement.InstanceName = "mymachine.local"; announcement.ServiceName = "_http._tcp.local."; announcement.Port = 80; announcement.TTL = TimeSpan.FromSeconds(30); service.AddAnnouncement(announcement);
3、搜索DNS解析记录:可以使用MulticastClient
类来搜索DNS解析记录。这个类提供了一个Lookup
方法
var client = new MulticastClient(IPAddress.Parse("224.0.0.251"), 5353);
var result = await client.Lookup("_http._tcp.local", "mymachine.local", TimeSpan.FromSeconds(5));
Console.WriteLine(result.Target);
标签:announcement,MDns,类来,C#,Multicast,DNS,var,new,local From: https://www.cnblogs.com/chengeng/p/17851665.html