You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.2 KiB
70 lines
2.2 KiB
using System.Net;
|
|
using System.Net.Sockets;
|
|
using Microsoft.AspNetCore.HttpOverrides;
|
|
|
|
namespace MediaBrowser.Common.Net
|
|
{
|
|
/// <summary>
|
|
/// Base network object class.
|
|
/// </summary>
|
|
public class IPData
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="IPData"/> class.
|
|
/// </summary>
|
|
/// <param name="address">An <see cref="IPAddress"/>.</param>
|
|
/// <param name="subnet">The <see cref="IPNetwork"/>.</param>
|
|
/// <param name="name">The object's name.</param>
|
|
public IPData(IPAddress address, IPNetwork? subnet, string name)
|
|
{
|
|
Address = address;
|
|
Subnet = subnet ?? (address.AddressFamily == AddressFamily.InterNetwork ? new IPNetwork(address, 32) : new IPNetwork(address, 128));
|
|
Name = name;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="IPData"/> class.
|
|
/// </summary>
|
|
/// <param name="address">An <see cref="IPAddress"/>.</param>
|
|
/// <param name="subnet">The <see cref="IPNetwork"/>.</param>
|
|
public IPData(IPAddress address, IPNetwork? subnet)
|
|
: this(address, subnet, string.Empty)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the object's IP address.
|
|
/// </summary>
|
|
public IPAddress Address { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the object's IP address.
|
|
/// </summary>
|
|
public IPNetwork Subnet { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the interface index.
|
|
/// </summary>
|
|
public int Index { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the interface name.
|
|
/// </summary>
|
|
public string Name { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets the AddressFamily of this object.
|
|
/// </summary>
|
|
public AddressFamily AddressFamily
|
|
{
|
|
get
|
|
{
|
|
return Address.Equals(IPAddress.None)
|
|
? (Subnet.Prefix.AddressFamily.Equals(IPAddress.None)
|
|
? AddressFamily.Unspecified : Subnet.Prefix.AddressFamily)
|
|
: Address.AddressFamily;
|
|
}
|
|
}
|
|
}
|
|
}
|