filter ip addresses
This commit is contained in:
parent
2f40910c90
commit
0911bebf22
|
@ -231,6 +231,7 @@ namespace MediaBrowser.Common.Implementations.Networking
|
|||
var properties = network.GetIPProperties();
|
||||
|
||||
return properties.UnicastAddresses
|
||||
.Where(i => i.IsDnsEligible)
|
||||
.Select(i => i.Address)
|
||||
.Where(i => i.AddressFamily == AddressFamily.InterNetwork)
|
||||
.ToList();
|
||||
|
|
|
@ -11,6 +11,7 @@ using System.Net.NetworkInformation;
|
|||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MoreLinq;
|
||||
|
||||
namespace MediaBrowser.Dlna.Ssdp
|
||||
|
@ -27,52 +28,21 @@ namespace MediaBrowser.Dlna.Ssdp
|
|||
|
||||
public event EventHandler<SsdpMessageEventArgs> DeviceDiscovered;
|
||||
public event EventHandler<SsdpMessageEventArgs> DeviceLeft;
|
||||
private readonly INetworkManager _networkManager;
|
||||
|
||||
public DeviceDiscovery(ILogger logger, IServerConfigurationManager config, IServerApplicationHost appHost)
|
||||
public DeviceDiscovery(ILogger logger, IServerConfigurationManager config, IServerApplicationHost appHost, INetworkManager networkManager)
|
||||
{
|
||||
_tokenSource = new CancellationTokenSource();
|
||||
|
||||
_logger = logger;
|
||||
_config = config;
|
||||
_appHost = appHost;
|
||||
_networkManager = networkManager;
|
||||
}
|
||||
|
||||
private List<IPAddress> GetLocalIpAddresses()
|
||||
{
|
||||
NetworkInterface[] interfaces;
|
||||
|
||||
try
|
||||
{
|
||||
interfaces = NetworkInterface.GetAllNetworkInterfaces();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error in GetAllNetworkInterfaces", ex);
|
||||
return new List<IPAddress>();
|
||||
}
|
||||
|
||||
return interfaces.SelectMany(network => {
|
||||
|
||||
try
|
||||
{
|
||||
_logger.Debug("Querying interface: {0}. Type: {1}. Status: {2}", network.Name, network.NetworkInterfaceType, network.OperationalStatus);
|
||||
|
||||
var properties = network.GetIPProperties();
|
||||
|
||||
return properties.UnicastAddresses
|
||||
.Select(i => i.Address)
|
||||
.Where(i => i.AddressFamily == AddressFamily.InterNetwork)
|
||||
.ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error querying network interface", ex);
|
||||
return new List<IPAddress>();
|
||||
}
|
||||
|
||||
})
|
||||
.DistinctBy(i => i.ToString())
|
||||
.ToList();
|
||||
return _networkManager.GetLocalIpAddresses().ToList();
|
||||
}
|
||||
|
||||
public void Start(SsdpHandler ssdpHandler)
|
||||
|
|
|
@ -522,7 +522,7 @@ namespace MediaBrowser.Server.Startup.Common
|
|||
SubtitleManager = new SubtitleManager(LogManager.GetLogger("SubtitleManager"), FileSystemManager, LibraryMonitor, LibraryManager, MediaSourceManager);
|
||||
RegisterSingleInstance(SubtitleManager);
|
||||
|
||||
RegisterSingleInstance<IDeviceDiscovery>(new DeviceDiscovery(LogManager.GetLogger("IDeviceDiscovery"), ServerConfigurationManager, this));
|
||||
RegisterSingleInstance<IDeviceDiscovery>(new DeviceDiscovery(LogManager.GetLogger("IDeviceDiscovery"), ServerConfigurationManager, this, NetworkManager));
|
||||
|
||||
ChapterManager = new ChapterManager(LibraryManager, LogManager.GetLogger("ChapterManager"), ServerConfigurationManager, ItemRepository);
|
||||
RegisterSingleInstance(ChapterManager);
|
||||
|
|
Loading…
Reference in New Issue
Block a user