using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Net; using System.Net.NetworkInformation; using MediaBrowser.Model.Net; using Microsoft.AspNetCore.Http; namespace MediaBrowser.Common.Net { /// /// Interface for the NetworkManager class. /// public interface INetworkManager { /// /// Event triggered on network changes. /// event EventHandler NetworkChanged; /// /// Gets a value indicating whether IPv4 is enabled. /// bool IsIPv4Enabled { get; } /// /// Gets a value indicating whether IPv6 is enabled. /// bool IsIPv6Enabled { get; } /// /// Calculates the list of interfaces to use for Kestrel. /// /// A IReadOnlyList{IPData} object containing all the interfaces to bind. /// If all the interfaces are specified, and none are excluded, it returns zero items /// to represent any address. /// When false, return or for all interfaces. IReadOnlyList GetAllBindInterfaces(bool individualInterfaces = false); /// /// Returns a list containing the loopback interfaces. /// /// IReadOnlyList{IPData}. IReadOnlyList GetLoopbacks(); /// /// Retrieves the bind address to use in system URLs. (Server Discovery, PlayTo, LiveTV, SystemInfo) /// If no bind addresses are specified, an internal interface address is selected. /// The priority of selection is as follows:- /// /// The value contained in the startup parameter --published-server-url. /// /// If the user specified custom subnet overrides, the correct subnet for the source address. /// /// If the user specified bind interfaces to use:- /// The bind interface that contains the source subnet. /// The first bind interface specified that suits best first the source's endpoint. eg. external or internal. /// /// If the source is from a public subnet address range and the user hasn't specified any bind addresses:- /// The first public interface that isn't a loopback and contains the source subnet. /// The first public interface that isn't a loopback. /// The first internal interface that isn't a loopback. /// /// If the source is from a private subnet address range and the user hasn't specified any bind addresses:- /// The first private interface that contains the source subnet. /// The first private interface that isn't a loopback. /// /// If no interfaces meet any of these criteria, then a loopback address is returned. /// /// Interfaces that have been specifically excluded from binding are not used in any of the calculations. /// /// Source of the request. /// Optional port returned, if it's part of an override. /// IP address to use, or loopback address if all else fails. string GetBindAddress(HttpRequest source, out int? port); /// /// Retrieves the bind address to use in system URLs. (Server Discovery, PlayTo, LiveTV, SystemInfo) /// If no bind addresses are specified, an internal interface address is selected. /// /// IP address of the request. /// Optional port returned, if it's part of an override. /// Optional boolean denoting if published server overrides should be ignored. Defaults to false. /// IP address to use, or loopback address if all else fails. string GetBindAddress(IPAddress? source, out int? port, bool skipOverrides = false); /// /// Retrieves the bind address to use in system URLs. (Server Discovery, PlayTo, LiveTV, SystemInfo) /// If no bind addresses are specified, an internal interface address is selected. /// (See . /// /// Source of the request. /// Optional port returned, if it's part of an override. /// IP address to use, or loopback address if all else fails. string GetBindAddress(string source, out int? port); /// /// Get a list of all the MAC addresses associated with active interfaces. /// /// List of MAC addresses. IReadOnlyList GetMacAddresses(); /// /// Returns true if the address is part of the user defined LAN. /// /// IP to check. /// True if endpoint is within the LAN range. bool IsInLocalNetwork(string address); /// /// Returns true if the address is part of the user defined LAN. /// /// IP to check. /// True if endpoint is within the LAN range. bool IsInLocalNetwork(IPAddress address); /// /// Attempts to convert the interface name to an IP address. /// eg. "eth1", or "enp3s5". /// /// Interface name. /// Resulting object's IP addresses, if successful. /// Success of the operation. bool TryParseInterface(string intf, [NotNullWhen(true)] out IReadOnlyList? result); /// /// Returns all internal (LAN) bind interface addresses. /// /// An list of internal (LAN) interfaces addresses. IReadOnlyList GetInternalBindAddresses(); /// /// Checks if has access to the server. /// /// IP address of the client. /// True if it has access, otherwise false. bool HasRemoteAccess(IPAddress remoteIP); } }