diff options
| author | randomevents <ross.phillip.m@gmail.com> | 2017-10-10 23:35:30 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-10-10 23:35:30 -0400 |
| commit | 329305230eb0b0f12e5de4cdb04188dcb89e4a0c (patch) | |
| tree | d8c57b188762bb4ed4a0fa9c2e2228843a5f8b69 /Emby.Server.Implementations/Networking/NetworkManager.cs | |
| parent | 3c7ee764eca1d5babe648a7d98a711bebaf17e3f (diff) | |
Test for matching subnet of IP's (VPN request)
test available ip4 host address against the endpoint (only local addresses, 10 127 192.68 169), if there's a preliminary match, it finds the subnet of the host ip (255.255.255.0) and makes sure's there's a match between host (255.255.255) and endpoint
Diffstat (limited to 'Emby.Server.Implementations/Networking/NetworkManager.cs')
| -rw-r--r-- | Emby.Server.Implementations/Networking/NetworkManager.cs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/Emby.Server.Implementations/Networking/NetworkManager.cs b/Emby.Server.Implementations/Networking/NetworkManager.cs index 5fb8f7fc9..7f0eef0b9 100644 --- a/Emby.Server.Implementations/Networking/NetworkManager.cs +++ b/Emby.Server.Implementations/Networking/NetworkManager.cs @@ -93,12 +93,36 @@ namespace Emby.Server.Implementations.Networking } return - endpoint.StartsWith("localhost", StringComparison.OrdinalIgnoreCase) || + IsInPrivateAddressSpaceAndLocalSubnet(endpoint); + } + + public bool IsInPrivateAddressSpaceAndLocalSubnet(string endpoint) + { + 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); + endpoint.StartsWith("169.", StringComparison.OrdinalIgnoreCase) + ) + { + foreach (NetworkInterface adapter in NetworkInterface.GetAllNetworkInterfaces()) + foreach (UnicastIPAddressInformation unicastIPAddressInformation in adapter.GetIPProperties().UnicastAddresses) + if (unicastIPAddressInformation.Address.AddressFamily == AddressFamily.InterNetwork && endpoint.Split('.')[0] == unicastIPAddressInformation.Address.ToString().Split('.')[0]) + { + int subnet_Test = 0; + foreach (string part in unicastIPAddressInformation.IPv4Mask.ToString().Split('.')) + { + if (part.Equals("0")) break; + subnet_Test++; + } + + subnet_Match = String.Join(".", unicastIPAddressInformation.Address.ToString().Split('.').Take(subnet_Test).ToArray()); + } + } + + return endpoint.StartsWith(subnet_Match + ".", StringComparison.OrdinalIgnoreCase); } private bool Is172AddressPrivate(string endpoint) |
