C#/。NET:找出一台服务器是否存在,查询的DNS SVC记录一台、是否存在、服务器、NET

2023-09-05 02:22:36 作者:现实太假,人心太狗

编写cleint /服务器的工具,我负责试图找到一台服务器连接到。我很想让事情尽可能的简单用户。因此,我的想法是:

Writing a cleint/Server tool I am tasked trying to find a server to connect to. I would love to make things as easy as possible for the user. As such, my idea is to:

检查特定的服务器(codeD的名字)是否存在(如mail.xxx的邮件服务器,例如 - 我exampüle不是邮件服务器;) 查询否则为DNS SVC记录,使管理员可以配置特定serivce服务器位置(即客户端连接到)。

其结果是,用户可能必须输入只有一个域名,甚至可能甚至没有(使用计算机在局域网环境中的注册标准的域)。

The result is that the user may have to enter only a domain name, possibly even not even that (using the registered standard domain of the computer in a LAN environment).

任何想法如何:

要了解服务器是否存在及答案(即在线)的最快方法是什么? TCP可能需要很长的时间,如果服务器不存在。一个UDP风格平听起来是个好主意,我。 PING本身可能无法使用。 Anyonw知道怎么问,从withint .NET最好的SVC记录在一个特定的(默认)域?

推荐答案

最好的方法来测试,如果一个服务存在且是活的很可​​能使用该服务的本地协议。否则,我会去的平(ICMP ECHO)。

The best way to test if a service exists and is alive is probably using the native protocol of that service. Otherwise I would go with ping (ICMP ECHO).

作为用于查找SRV记录(我假设你的意思是SRVsinces没有SVC型),您可以使用DNS客户端库为.NET( http://www.simpledns.com/dns-client-lib.aspx ) - 例如:

As for looking up the SRV-record (I assume you mean "SRV" sinces there is no "SVC" type), you could use the "DNS Client Library for .NET" (http://www.simpledns.com/dns-client-lib.aspx) - for example:

var Response = JHSoftware.DnsClient.Lookup("_ftp._tcp.xyz.com", 
                                       JHSoftware.DnsClient.RecordType.SRV);