@ SuppressWarnings ( "deprecation" ) public static String getPublicIP ( XMPPConnection xmppConnection ) throws NotConnectedException , InterruptedException { if ( ! xmppConnection . isConnected ( ) ) { return null ; } RTPBridge rtpPacket = new RTPBridge ( RTPBridge . BridgeAction . publicip ) ; rtpPacket . setTo ( RTPBridge . NAME + "." + xmppConnection . getXMPPServiceDomain ( ) ) ; rtpPacket . setType ( Type . set ) ; // LOGGER.debug("Relayed to: " + candidate.getIp() + ":" + candidate.getPort()); StanzaCollector collector = xmppConnection . createStanzaCollectorAndSend ( rtpPacket ) ; RTPBridge response = collector . nextResult ( ) ; // Cancel the collector. collector . cancel ( ) ; if ( response == null ) return null ; if ( response . getIp ( ) == null || response . getIp ( ) . equals ( "" ) ) return null ; Enumeration < NetworkInterface > ifaces = null ; try { ifaces = NetworkInterface . getNetworkInterfaces ( ) ; } catch ( SocketException e ) { LOGGER . log ( Level . WARNING , "exception" , e ) ; } while ( ifaces != null && ifaces . hasMoreElements ( ) ) { NetworkInterface iface = ifaces . nextElement ( ) ; Enumeration < InetAddress > iaddresses = iface . getInetAddresses ( ) ; while ( iaddresses . hasMoreElements ( ) ) { InetAddress iaddress = iaddresses . nextElement ( ) ; if ( ! iaddress . isLoopbackAddress ( ) ) if ( iaddress . getHostAddress ( ) . indexOf ( response . getIp ( ) ) >= 0 ) return null ; } } return response . getIp ( ) ; }
Get Public Address from the Server .