/// <summary> /// Retrieves an enumerable collection of th XMPP client's external IP /// addresses. /// </summary> /// <returns>An enumerable collection of the XMPP client's external IP /// addresses.</returns> /// <exception cref="NotSupportedException">The external IP address(es) /// could not be determined.</exception> /// <remarks>In simple configurations this should usually yield one external /// IP address only.</remarks> private async Task <IEnumerable <IPAddress> > GetExternalAddresses() { // Use a set so we don't get duplicate addresses. ISet <IPAddress> set = new HashSet <IPAddress>(); try { set.Add(await serverIpCheck.GetExternalAddress()); } catch { // Fall through if server does not support the 'Server IP Check' extension. } // Next, try to retrieve external IP addresses from UPnP-enabled devices. if (UseUPnP) { throw new NotImplementedException(".net Core version doesn't support UPnP"); } // Finally, perform a STUN query. try { set.Add(await StunClient.Query(StunServer.Host, StunServer.Port, 3000)); } catch { // Nothing to do here. } // See if we could gather any external addresses at all. if (set.Count == 0) { throw new NotSupportedException("The external IP address(es) could not " + "be obtained."); } return(set); }
/// <summary> /// Retrieves an enumerable collection of th XMPP client's external IP /// addresses. /// </summary> /// <returns>An enumerable collection of the XMPP client's external IP /// addresses.</returns> /// <exception cref="NotSupportedException">The external IP address(es) /// could not be determined.</exception> /// <remarks>In simple configurations this should usually yield one external /// IP address only.</remarks> private IEnumerable <IPAddress> GetExternalAddresses() { // Use a set so we don't get duplicate addresses. ISet <IPAddress> set = new HashSet <IPAddress>(); try { set.Add(serverIpCheck.GetExternalAddress()); } catch { // Fall through if server does not support the 'Server IP Check' extension. } // Next, try to retrieve external IP addresses from UPnP-enabled devices. if (UseUPnP) { #if WINDOWSPLATFORM try { foreach (var address in UPnP.GetExternalAddresses()) { set.Add(address); } } catch (Exception) { // Fall through in case any device querying goes wrong. } #endif } // Finally, perform a STUN query. try { set.Add(StunClient.Query(StunServer.Host, StunServer.Port, 3000)); } catch { // Nothing to do here. } // See if we could gather any external addresses at all. if (set.Count == 0) { throw new NotSupportedException("The external IP address(es) could not " + "be obtained."); } return(set); }