diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-09-16 23:04:10 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-09-16 23:04:10 -0400 |
| commit | 6130cb2403662596bba0474494372446d9caa3c3 (patch) | |
| tree | 8068a437340aa7e904965caf7e50053c433623d0 /MediaBrowser.ServerApplication | |
| parent | 5363cb2719752732db17199ce9ed27743f0a80a1 (diff) | |
adjust discovery of local ip addresses
Diffstat (limited to 'MediaBrowser.ServerApplication')
| -rw-r--r-- | MediaBrowser.ServerApplication/ApplicationHost.cs | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 25d410bfc7..e05ae9fa16 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -950,17 +950,8 @@ namespace MediaBrowser.ServerApplication /// <returns>System.String.</returns> private string GetLocalIpAddress() { - var localAddresses = NetworkManager.GetLocalIpAddresses().ToList(); - - // Cross-check the local ip addresses with addresses that have been received on with the http server - var matchedAddress = HttpServer.LocalEndPoints - .ToList() - .Select(i => i.Split(':').FirstOrDefault()) - .Where(i => !string.IsNullOrEmpty(i)) - .FirstOrDefault(i => localAddresses.Contains(i, StringComparer.OrdinalIgnoreCase)); - // Return the first matched address, if found, or the first known local address - var address = matchedAddress ?? localAddresses.FirstOrDefault(); + var address = HttpServerIpAddresses.FirstOrDefault(); if (!string.IsNullOrWhiteSpace(address)) { @@ -972,6 +963,37 @@ namespace MediaBrowser.ServerApplication return address; } + public IEnumerable<string> HttpServerIpAddresses + { + get + { + var localAddresses = NetworkManager.GetLocalIpAddresses() + .ToList(); + + if (localAddresses.Count < 2) + { + return localAddresses; + } + + var httpServerAddresses = HttpServer.LocalEndPoints + .Select(i => i.Split(':').FirstOrDefault()) + .Where(i => !string.IsNullOrEmpty(i)) + .ToList(); + + // Cross-check the local ip addresses with addresses that have been received on with the http server + var matchedAddresses = httpServerAddresses + .Where(i => localAddresses.Contains(i, StringComparer.OrdinalIgnoreCase)) + .ToList(); + + if (matchedAddresses.Count == 0) + { + return localAddresses.Take(1); + } + + return matchedAddresses; + } + } + public string FriendlyName { get |
