Pregunta

Estoy escribiendo Android aplicación y necesidad de conocer mi IP pública. En mi aplicación que estoy usando Smack biblioteca para la conversación con el servidor XMPP (que era necesario no sólo para conocer mi IP)

Mensaje de Bind, recibido del servidor miradas como:

<iq id="_xmpp_bind1" type="result">
   <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
      <jid>user@jabber.example.com/Smack</jid>
   </bind>
</iq>

Pero estoy esperando que parece:

<iq id="_xmpp_bind1" type="result">
    <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
       <jid>user@jabber.example.com/11.22.33.44:12345</jid
    </bind>
</iq>

Cuando en lugar de 11.22.33.44 debería ser mi IP pública.

¿Fue útil?

Solución 2

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

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top