mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-31 14:33:54 -04:00
update local network detection
This commit is contained in:
parent
e6329c46d1
commit
8e41918ac5
@ -84,7 +84,15 @@ namespace MediaBrowser.Common.Implementations.Networking
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsInPrivateAddressSpace(string endpoint)
|
private bool IsInPrivateAddressSpaceIpv6(string endpoint)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
|
||||||
|
// If url was requested with computer name, we may see this
|
||||||
|
string.Equals(endpoint, "::1", StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsInPrivateAddressSpaceIpv4(string endpoint)
|
||||||
{
|
{
|
||||||
// Private address space:
|
// Private address space:
|
||||||
// http://en.wikipedia.org/wiki/Private_network
|
// http://en.wikipedia.org/wiki/Private_network
|
||||||
@ -96,9 +104,6 @@ namespace MediaBrowser.Common.Implementations.Networking
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
// If url was requested with computer name, we may see this
|
|
||||||
endpoint.IndexOf("::", StringComparison.OrdinalIgnoreCase) != -1 ||
|
|
||||||
|
|
||||||
endpoint.StartsWith("localhost", StringComparison.OrdinalIgnoreCase) ||
|
endpoint.StartsWith("localhost", StringComparison.OrdinalIgnoreCase) ||
|
||||||
endpoint.StartsWith("127.", StringComparison.OrdinalIgnoreCase) ||
|
endpoint.StartsWith("127.", StringComparison.OrdinalIgnoreCase) ||
|
||||||
endpoint.StartsWith("10.", StringComparison.OrdinalIgnoreCase) ||
|
endpoint.StartsWith("10.", StringComparison.OrdinalIgnoreCase) ||
|
||||||
@ -131,13 +136,28 @@ namespace MediaBrowser.Common.Implementations.Networking
|
|||||||
throw new ArgumentNullException("endpoint");
|
throw new ArgumentNullException("endpoint");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsInPrivateAddressSpace(endpoint))
|
IPAddress address;
|
||||||
|
if (IPAddress.TryParse(endpoint, out address))
|
||||||
|
{
|
||||||
|
int lengthMatch = 100;
|
||||||
|
if (address.AddressFamily == AddressFamily.InterNetwork)
|
||||||
|
{
|
||||||
|
lengthMatch = 4;
|
||||||
|
if (IsInPrivateAddressSpaceIpv4(endpoint))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if (address.AddressFamily == AddressFamily.InterNetworkV6)
|
||||||
|
{
|
||||||
|
lengthMatch = 10;
|
||||||
|
if (IsInPrivateAddressSpaceIpv6(endpoint))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const int lengthMatch = 4;
|
// Should be even be doing this with ipv6?
|
||||||
|
|
||||||
if (endpoint.Length >= lengthMatch)
|
if (endpoint.Length >= lengthMatch)
|
||||||
{
|
{
|
||||||
var prefix = endpoint.Substring(0, lengthMatch);
|
var prefix = endpoint.Substring(0, lengthMatch);
|
||||||
@ -148,8 +168,8 @@ namespace MediaBrowser.Common.Implementations.Networking
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
IPAddress address;
|
|
||||||
if (resolveHost && !IPAddress.TryParse(endpoint, out address))
|
if (resolveHost && !IPAddress.TryParse(endpoint, out address))
|
||||||
{
|
{
|
||||||
Uri uri;
|
Uri uri;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user