aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.ServerApplication/Networking/NetworkManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.ServerApplication/Networking/NetworkManager.cs')
-rw-r--r--MediaBrowser.ServerApplication/Networking/NetworkManager.cs47
1 files changed, 44 insertions, 3 deletions
diff --git a/MediaBrowser.ServerApplication/Networking/NetworkManager.cs b/MediaBrowser.ServerApplication/Networking/NetworkManager.cs
index e80c8ff3f..7a2e184b6 100644
--- a/MediaBrowser.ServerApplication/Networking/NetworkManager.cs
+++ b/MediaBrowser.ServerApplication/Networking/NetworkManager.cs
@@ -1,12 +1,13 @@
-using System.Globalization;
-using System.IO;
-using MediaBrowser.Common.Implementations.Networking;
+using MediaBrowser.Common.Implementations.Networking;
using MediaBrowser.Common.Net;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Net;
using System;
using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
using System.Linq;
+using System.Net;
using System.Runtime.InteropServices;
namespace MediaBrowser.ServerApplication.Networking
@@ -43,6 +44,46 @@ namespace MediaBrowser.ServerApplication.Networking
};
}
+ public bool IsInLocalNetwork(string endpoint)
+ {
+ if (string.IsNullOrWhiteSpace(endpoint))
+ {
+ throw new ArgumentNullException("endpoint");
+ }
+
+ IPAddress address;
+ if (!IPAddress.TryParse(endpoint, out address))
+ {
+ return true;
+ }
+
+ const int lengthMatch = 4;
+
+ if (endpoint.Length >= lengthMatch)
+ {
+ var prefix = endpoint.Substring(0, lengthMatch);
+
+ if (GetLocalIpAddresses()
+ .Any(i => i.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)))
+ {
+ return true;
+ }
+ }
+
+ // Private address space:
+ // http://en.wikipedia.org/wiki/Private_network
+
+ return
+
+ // If url was requested with computer name, we may see this
+ endpoint.IndexOf("::", StringComparison.OrdinalIgnoreCase) != -1 ||
+
+ endpoint.StartsWith("10.", StringComparison.OrdinalIgnoreCase) ||
+ endpoint.StartsWith("192.", StringComparison.OrdinalIgnoreCase) ||
+ endpoint.StartsWith("172.", StringComparison.OrdinalIgnoreCase) ||
+ endpoint.StartsWith("169.", StringComparison.OrdinalIgnoreCase);
+ }
+
/// <summary>
/// To the type of the network share.
/// </summary>