如何检查服务器是否支持xmpp协议?

发布于 2024-07-25 21:51:05 字数 88 浏览 2 评论 0原文

我正在寻找一种方法来检查服务器是否支持 xmpp 协议,即 xmpp-server 正在该域上运行。

也许是特殊的 DNS 检查或类似的东西?

I'm looking for a way to check if a server is support xmpp protocol, i.e. xmpp-server is running on this domain.

Maybe special DNS check or something like that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笔芯 2024-08-01 21:51:05

大多数 XMPP 服务器应至少支持以下 DNS SRV 记录之一:

  • _xmpp-server._tcp.example.com
  • _xmpp-client._tcpexample.com

某些服务器可能没有发布这些记录,但其中大多数服务器不想与外界通信。 例如,您可以在命令行上使用“dig”来检查域,如下所示:

% dig +short -t SRV _xmpp-server._tcp.gmail.com.
20 0 5269 xmpp-server2.l.google.com.
20 0 5269 xmpp-server3.l.google.com.
20 0 5269 xmpp-server4.l.google.com.
5 0 5269 xmpp-server.l.google.com.
20 0 5269 xmpp-server1.l.google.com.

“+short”删除大量 DNS 详细信息,“-t SRV”表示我们需要 SRV 记录,点位于最后说忽略你的本地域名设置。

(响应@user188719添加)
如果没有找到SRV记录,您可以尝试使用原始域名,并假设端口5222用于客户端连接或5269用于服务器连接。

获得要连接的主机名和端口号后,您可以使用 telnet 主机名端口 来查看是否有进程正在侦听。 但是,要真正检测该主机/端口是否是 XMPP 服务器,请在 XMPP 流的开头发送。 ncnetcat 为此提供了一种方便的机制。 服务器到服务器检查的示例:

% echo "<stream:stream to='gmail.com' version='1.0' xmlns='jabber:server' xmlns:stream='http://etherx.jabber.org/streams' xmlns:db='jabber:server:dialback'>" | nc xmpp-server.l.google.com 5269
<stream:stream id="0A44AFB86521393A" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:server" xmlns:db="jabber:server:dialback">

Most XMPP servers should support at least one of these DNS SRV records:

  • _xmpp-server._tcp.example.com
  • _xmpp-client._tcp.example.com

Some servers may not have these records published, but most of those will not want to talk to the outside world. As an example, you can use "dig" on the command line to check a domain, like this:

% dig +short -t SRV _xmpp-server._tcp.gmail.com.
20 0 5269 xmpp-server2.l.google.com.
20 0 5269 xmpp-server3.l.google.com.
20 0 5269 xmpp-server4.l.google.com.
5 0 5269 xmpp-server.l.google.com.
20 0 5269 xmpp-server1.l.google.com.

"+short" gets rid of a lot of DNS details, "-t SRV" says we want SRV records, and the dot at the end says to ignore your local domain name settings.

(adding in response to @user188719)
If you don't find an SRV record, you can try using the original domain name, and assuming port 5222 for client connections or 5269 for server connections.

Once you have the hostname and port number to connect to, you can use telnet hostname port to see if there is a process listening there. However, to really detect if it's an XMPP server at that host/port, send in the start of an XMPP stream. nc or netcat provide a convenient mechanism for this. Example for a server-to-server check:

% echo "<stream:stream to='gmail.com' version='1.0' xmlns='jabber:server' xmlns:stream='http://etherx.jabber.org/streams' xmlns:db='jabber:server:dialback'>" | nc xmpp-server.l.google.com 5269
<stream:stream id="0A44AFB86521393A" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:server" xmlns:db="jabber:server:dialback">
×眷恋的温暖 2024-08-01 21:51:05

按照 Joe 的解释,我个人会检查 SRV 记录并回退到端口 5269 上的快速(短超时)连接检查。然后缓存结果。

Following Joe's explanation, I personally would check SRV records and fall back to a quick (short timeout) connect check on port 5269. Then cache the result.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文