如何从 XMPP 绑定消息获取我的公共 IP?

发布于 2024-10-08 02:54:43 字数 934 浏览 0 评论 0原文

我正在编写 Android 应用程序,需要知道我的公共 IP。在我的应用程序中,我使用 Smack 库与 XMPP 服务器进行对话(这不仅需要知道我的 IP)

从服务器收到的绑定消息看起来像:

<iq id="_xmpp_bind1" type="result">
   <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
      <jid>[email protected]/Smack</jid>
   </bind>
</iq>

但我正在等待它看起来像:

<iq id="_xmpp_bind1" type="result">
    <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
       <jid>[email protected]/11.22.33.44:12345</jid
    </bind>
</iq>

其中而不是 11.22.33.44 应该是我的公共 IP。

I'm writing Android app and need to know my public IP. In my app i'm using Smack library for conversation with XMPP server (that needed not only to know my IP)

Bind message, received from server looks like:

<iq id="_xmpp_bind1" type="result">
   <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
      <jid>[email protected]/Smack</jid>
   </bind>
</iq>

But I'm waiting it looks like:

<iq id="_xmpp_bind1" type="result">
    <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
       <jid>[email protected]/11.22.33.44:12345</jid
    </bind>
</iq>

Where instead of 11.22.33.44 should be my public IP.

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

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

发布评论

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

评论(2

浅笑依然 2024-10-15 02:54:43

您使用什么 XMPP 服务器?

您可能希望以与您提议的不同的方式来解决这个问题。您的方法会将您的真实 IP 地址泄露给名册上的每个人。例如,对 http://ifconfig.me/ 的 HTTP 请求将返回您的外部 IP 地址,而无需任何额外的麻烦。

What XMPP server are you using?

It's likely you'd want to solve this a different way than you're proposing. Your approach would leak your real IP address to everyone on your roster. For example, an HTTP request to http://ifconfig.me/ will return your external IP address without any extra hassle.

倾城花音 2024-10-15 02:54:43

我找到了问题的原因。我的 Smack 库本身会激发服务器发送此类绑定响应。

它发送这样的绑定请求:

<iq id="Um486-7" type="set">
   <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
      <resource>Smack</resource>
   </bind>
</iq>

因此资源是由 Smack 的绑定请求显式指定的。
使用方法时会出现这种情况:

public void login (String username, String password)

为了避免这种行为,应该使用下一个方法:

public void login (String username, String password, String resource)

并且resource应该设置为null

I found the cause of problem. My Smack library itself provokes server to send such bind response.

It sends such bind request:

<iq id="Um486-7" type="set">
   <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
      <resource>Smack</resource>
   </bind>
</iq>

So resource is specified explicitly by Smack's bind request.
That situation is arises when using method:

public void login (String username, String password)

To avoid such behavior next method should be used:

public void login (String username, String password, String resource)

and resource should be set to null

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