diff options
Diffstat (limited to 'Emby.Server.Implementations/Networking/NetworkManager.cs')
| -rw-r--r-- | Emby.Server.Implementations/Networking/NetworkManager.cs | 70 |
1 files changed, 37 insertions, 33 deletions
diff --git a/Emby.Server.Implementations/Networking/NetworkManager.cs b/Emby.Server.Implementations/Networking/NetworkManager.cs index 66b2cba39..72d0154aa 100644 --- a/Emby.Server.Implementations/Networking/NetworkManager.cs +++ b/Emby.Server.Implementations/Networking/NetworkManager.cs @@ -103,7 +103,10 @@ namespace Emby.Server.Implementations.Networking } return endpoint.StartsWith("localhost", StringComparison.OrdinalIgnoreCase) || - endpoint.StartsWith("127.0.0.1", StringComparison.OrdinalIgnoreCase) || + endpoint.StartsWith("127.", StringComparison.OrdinalIgnoreCase) || + endpoint.StartsWith("192.168", StringComparison.OrdinalIgnoreCase) || + endpoint.StartsWith("169.", StringComparison.OrdinalIgnoreCase) || + endpoint.StartsWith("10.", StringComparison.OrdinalIgnoreCase) || IsInPrivateAddressSpaceAndLocalSubnet(endpoint); } @@ -111,46 +114,42 @@ namespace Emby.Server.Implementations.Networking { var endpointFirstPart = endpoint.Split('.')[0]; - string subnet_Match = ""; - if ( - endpoint.StartsWith("127.", StringComparison.OrdinalIgnoreCase) || - endpoint.StartsWith("10.", StringComparison.OrdinalIgnoreCase) || - endpoint.StartsWith("192.168", StringComparison.OrdinalIgnoreCase) || - endpoint.StartsWith("169.", StringComparison.OrdinalIgnoreCase) - ) + if (endpoint.StartsWith("10.", StringComparison.OrdinalIgnoreCase)) { - foreach (NetworkInterface adapter in NetworkInterface.GetAllNetworkInterfaces()) - foreach (UnicastIPAddressInformation unicastIPAddressInformation in adapter.GetIPProperties().UnicastAddresses) - if (unicastIPAddressInformation.Address.AddressFamily == AddressFamily.InterNetwork && endpointFirstPart == unicastIPAddressInformation.Address.ToString().Split('.')[0]) - { - int subnet_Test = 0; - foreach (string part in unicastIPAddressInformation.IPv4Mask.ToString().Split('.')) - { - if (part.Equals("0")) break; - subnet_Test++; - } + var subnets = GetSubnets(endpointFirstPart); - subnet_Match = String.Join(".", unicastIPAddressInformation.Address.ToString().Split('.').Take(subnet_Test).ToArray()); - } + foreach (var subnet_Match in subnets) + { + //Logger.Debug("subnet_Match:" + subnet_Match); + + if (endpoint.StartsWith(subnet_Match + ".", StringComparison.OrdinalIgnoreCase)) + { + return true; + } + } } - return endpoint.StartsWith(subnet_Match + ".", StringComparison.OrdinalIgnoreCase); + return false; } - private Dictionary<string, string> _subnetLookup = new Dictionary<string, string>(StringComparer.Ordinal); - private string GetSubnet(string endpointFirstPart) + private Dictionary<string, List<string>> _subnetLookup = new Dictionary<string, List<string>>(StringComparer.Ordinal); + private List<string> GetSubnets(string endpointFirstPart) { - string subnet_Match = ""; + List<string> subnets; lock (_subnetLookup) { - if (_subnetLookup.TryGetValue(endpointFirstPart, out subnet_Match)) + if (_subnetLookup.TryGetValue(endpointFirstPart, out subnets)) { - return subnet_Match; + return subnets; } + subnets = new List<string>(); + foreach (NetworkInterface adapter in NetworkInterface.GetAllNetworkInterfaces()) + { foreach (UnicastIPAddressInformation unicastIPAddressInformation in adapter.GetIPProperties().UnicastAddresses) + { if (unicastIPAddressInformation.Address.AddressFamily == AddressFamily.InterNetwork && endpointFirstPart == unicastIPAddressInformation.Address.ToString().Split('.')[0]) { int subnet_Test = 0; @@ -160,16 +159,21 @@ namespace Emby.Server.Implementations.Networking subnet_Test++; } - subnet_Match = String.Join(".", unicastIPAddressInformation.Address.ToString().Split('.').Take(subnet_Test).ToArray()); - } + var subnet_Match = String.Join(".", unicastIPAddressInformation.Address.ToString().Split('.').Take(subnet_Test).ToArray()); - if (!string.IsNullOrWhiteSpace(subnet_Match)) - { - _subnetLookup[endpointFirstPart] = subnet_Match; + // TODO: Is this check necessary? + if (adapter.OperationalStatus == OperationalStatus.Up) + { + subnets.Add(subnet_Match); + } + } + } } - } - return subnet_Match; + _subnetLookup[endpointFirstPart] = subnets; + + return subnets; + } } private bool Is172AddressPrivate(string endpoint) |
