diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-05-27 14:34:03 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-05-27 14:34:03 -0400 |
| commit | 085e597a2e0be1aa7341946201de774684031dd4 (patch) | |
| tree | ad3e6ccd9d850e83b51e0dd1998bdca742be17d0 /MediaBrowser.Common.Implementations/NetworkManagement/NetworkManager.cs | |
| parent | d4e3c6aa52fe0bac50cb742d7fb082a61a66eb33 (diff) | |
improve accuracy of local ip address discovery
Diffstat (limited to 'MediaBrowser.Common.Implementations/NetworkManagement/NetworkManager.cs')
| -rw-r--r-- | MediaBrowser.Common.Implementations/NetworkManagement/NetworkManager.cs | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/MediaBrowser.Common.Implementations/NetworkManagement/NetworkManager.cs b/MediaBrowser.Common.Implementations/NetworkManagement/NetworkManager.cs index 3c42d340b..6db00064c 100644 --- a/MediaBrowser.Common.Implementations/NetworkManagement/NetworkManager.cs +++ b/MediaBrowser.Common.Implementations/NetworkManagement/NetworkManager.cs @@ -1,11 +1,11 @@ -using System.Globalization; -using System.Management; -using MediaBrowser.Common.Net; +using MediaBrowser.Common.Net; using MediaBrowser.Model.Net; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.Linq; +using System.Management; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; @@ -21,18 +21,16 @@ namespace MediaBrowser.Common.Implementations.NetworkManagement /// Gets the machine's local ip address /// </summary> /// <returns>IPAddress.</returns> - public string GetLocalIpAddress() + public IEnumerable<string> GetLocalIpAddresses() { var host = Dns.GetHostEntry(Dns.GetHostName()); - var ip = host.AddressList.LastOrDefault(i => i.AddressFamily == AddressFamily.InterNetwork); - - if (ip == null) - { - return null; - } - - return ip.ToString(); + // Reverse them because the last one is usually the correct one + // It's not fool-proof so ultimately the consumer will have to examine them and decide + return host.AddressList + .Where(i => i.AddressFamily == AddressFamily.InterNetwork) + .Select(i => i.ToString()) + .Reverse(); } /// <summary> |
