INetworkManager.cs 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Net;
  5. using System.Net.NetworkInformation;
  6. namespace MediaBrowser.Common.Net
  7. {
  8. public interface INetworkManager
  9. {
  10. event EventHandler NetworkChanged;
  11. /// <summary>
  12. /// Gets or sets a function to return the list of user defined LAN addresses.
  13. /// </summary>
  14. Func<string[]> LocalSubnetsFn { get; set; }
  15. /// <summary>
  16. /// Gets a random port TCP number that is currently available.
  17. /// </summary>
  18. /// <returns>System.Int32.</returns>
  19. int GetRandomUnusedTcpPort();
  20. /// <summary>
  21. /// Gets a random port UDP number that is currently available.
  22. /// </summary>
  23. /// <returns>System.Int32.</returns>
  24. int GetRandomUnusedUdpPort();
  25. /// <summary>
  26. /// Returns the MAC Address from first Network Card in Computer.
  27. /// </summary>
  28. /// <returns>The MAC Address.</returns>
  29. List<PhysicalAddress> GetMacAddresses();
  30. /// <summary>
  31. /// Determines whether [is in private address space] [the specified endpoint].
  32. /// </summary>
  33. /// <param name="endpoint">The endpoint.</param>
  34. /// <returns><c>true</c> if [is in private address space] [the specified endpoint]; otherwise, <c>false</c>.</returns>
  35. bool IsInPrivateAddressSpace(string endpoint);
  36. /// <summary>
  37. /// Determines whether [is in private address space 10.x.x.x] [the specified endpoint] and exists in the subnets returned by GetSubnets().
  38. /// </summary>
  39. /// <param name="endpoint">The endpoint.</param>
  40. /// <returns><c>true</c> if [is in private address space 10.x.x.x] [the specified endpoint]; otherwise, <c>false</c>.</returns>
  41. bool IsInPrivateAddressSpaceAndLocalSubnet(string endpoint);
  42. /// <summary>
  43. /// Determines whether [is in local network] [the specified endpoint].
  44. /// </summary>
  45. /// <param name="endpoint">The endpoint.</param>
  46. /// <returns><c>true</c> if [is in local network] [the specified endpoint]; otherwise, <c>false</c>.</returns>
  47. bool IsInLocalNetwork(string endpoint);
  48. /// <summary>
  49. /// Investigates an caches a list of interface addresses, excluding local link and LAN excluded addresses.
  50. /// </summary>
  51. /// <returns>The list of ipaddresses.</returns>
  52. IPAddress[] GetLocalIpAddresses();
  53. /// <summary>
  54. /// Checks if the given address falls within the ranges given in [subnets]. The addresses in subnets can be hosts or subnets in the CIDR format.
  55. /// </summary>
  56. /// <param name="addressString">The address to check.</param>
  57. /// <param name="subnets">If true, check against addresses in the LAN settings surrounded by brackets ([]).</param>
  58. /// <returns><c>true</c>if the address is in at least one of the given subnets, <c>false</c> otherwise.</returns>
  59. bool IsAddressInSubnets(string addressString, string[] subnets);
  60. /// <summary>
  61. /// Returns true if address is in the LAN list in the config file.
  62. /// </summary>
  63. /// <param name="address">The address to check.</param>
  64. /// <param name="excludeInterfaces">If true, check against addresses in the LAN settings which have [] arroud and return true if it matches the address give in address.</param>
  65. /// <param name="excludeRFC">If true, returns false if address is in the 127.x.x.x or 169.128.x.x range.</param>
  66. /// <returns><c>false</c>if the address isn't in the LAN list, <c>true</c> if the address has been defined as a LAN address.</returns>
  67. bool IsAddressInSubnets(IPAddress address, bool excludeInterfaces, bool excludeRFC);
  68. /// <summary>
  69. /// Checks if address is in the LAN list in the config file.
  70. /// </summary>
  71. /// <param name="address1">Source address to check.</param>
  72. /// <param name="address2">Destination address to check against.</param>
  73. /// <param name="subnetMask">Destination subnet to check against.</param>
  74. /// <returns><c>true/false</c>depending on whether address1 is in the same subnet as IPAddress2 with subnetMask.</returns>
  75. bool IsInSameSubnet(IPAddress address1, IPAddress address2, IPAddress subnetMask);
  76. /// <summary>
  77. /// Returns the subnet mask of an interface with the given address.
  78. /// </summary>
  79. /// <param name="address">The address to check.</param>
  80. /// <returns>Returns the subnet mask of an interface with the given address, or null if an interface match cannot be found.</returns>
  81. IPAddress GetLocalIpSubnetMask(IPAddress address);
  82. }
  83. }