using System.Threading.Tasks;
using System.Net.NetworkInformation;
using System.Net.Sockets;
namespace System.Net
{
/// Provides extension methods for sending Wake On LAN signals (magic packets) to a specific .
public static class IPAddressExtensions
{
private const int DefaultWolPort = 7;
#region Wol
/// Sends a Wake On LAN signal (magic packet) to a client.
/// Destination .
/// The MAC address of the client.
/// The port to send the packet to.
/// The length of the array is not 6.
/// is null.
/// An error occurred when accessing the socket. See Remarks section of for more information.
public static void SendWol(this IPAddress target, byte[] macAddress, int port) => target.SendWol(macAddress, port, null);
/// Sends a Wake On LAN signal (magic packet) to a client.
/// Destination .
/// The MAC address of the client.
/// The port to send the packet to.
/// The SecureOn password of the client.
/// The length of the array is not 6.
/// is null.
/// An error occurred when accessing the socket. See Remarks section of for more information.
public static void SendWol(this IPAddress target, byte[] macAddress, int port, SecureOnPassword password)
{
Net.MagicPacket.Send(new IPEndPoint(target, port), macAddress, password);
}
/// Sends a Wake On LAN signal (magic packet) to a client.
/// Destination .
/// The MAC address of the client.
/// The length of the array is not 6.
/// is null.
/// An error occurred when accessing the socket. See Remarks section of for more information.
public static void SendWol(this IPAddress target, byte[] macAddress) => target.SendWol(macAddress, null);
/// Sends a Wake On LAN signal (magic packet) to a client.
/// Destination .
/// The MAC address of the client.
/// The SecureOn password of the client.
/// The length of the array is not 6.
/// is null.
/// An error occurred when accessing the socket. See Remarks section of for more information.
public static void SendWol(this IPAddress target, byte[] macAddress, SecureOnPassword password)
{
Net.MagicPacket.Send(new IPEndPoint(target, DefaultWolPort), macAddress, password);
}
/// Sends a Wake On LAN signal (magic packet) to a client.
/// Destination .
/// The MAC address of the client.
/// The length of the is not 6.
/// is null.
/// An error occurred when accessing the socket. See Remarks section of for more information.
public static void SendWol(this IPAddress target, PhysicalAddress macAddress) => target.SendWol(macAddress, null);
/// Sends a Wake On LAN signal (magic packet) to a client.
/// Destination .
/// The MAC address of the client.
/// The SecureOn password of the client.
/// The length of the is not 6.
/// is null.
/// An error occurred when accessing the socket. See Remarks section of for more information.
public static void SendWol(this IPAddress target, PhysicalAddress macAddress, SecureOnPassword password)
{
Net.MagicPacket.Send(new IPEndPoint(target, DefaultWolPort), macAddress, password);
}
#endregion
#region ARP
///
/// Sendet eine Anfrage über das ARP-Protokoll, um eine IP-Adresse in die Physikalische Adresse aufzulösen. Falls sich die physikalische Adresse bereits im Cache des Hosts befindet, wird diese zurückgegeben.
///
/// Destination .
/// Eine ArpRequestResult-Instanz, welche die Ergebnisse der Anfrage enthält.
public static ArpRequestResult SendArpRequest(this IPAddress destination) => ArpRequest.Send(destination);
#endregion
#region TAP
#region Wol
/// Sends a Wake On LAN signal (magic packet) to a client.
/// Destination .
/// The MAC address of the client.
/// The port to send the packet to.
/// The length of the array is not 6.
/// is null.
/// An asynchronous which sends a Wake On LAN signal (magic packet) to a client.
public static Task SendWolAsync(this IPAddress target, byte[] macAddress, int port) => target.SendWolAsync(macAddress, port, null);
/// Sends a Wake On LAN signal (magic packet) to a client.
/// Destination .
/// The MAC address of the client.
/// The port to send the packet to.
/// The SecureOn password of the client.
/// The length of the array is not 6.
/// is null.
/// An asynchronous which sends a Wake On LAN signal (magic packet) to a client.
public static Task SendWolAsync(this IPAddress target, byte[] macAddress, int port, SecureOnPassword password)
{
return Net.MagicPacket.SendAsync(new IPEndPoint(target, port), macAddress, password);
}
/// Sends a Wake On LAN signal (magic packet) to a client.
/// Destination .
/// The MAC address of the client.
/// The length of the array is not 6.
/// is null.
/// An asynchronous which sends a Wake On LAN signal (magic packet) to a client.
public static Task SendWolAsync(this IPAddress target, byte[] macAddress) => target.SendWolAsync(macAddress, null);
/// Sends a Wake On LAN signal (magic packet) to a client.
/// Destination .
/// The MAC address of the client.
/// The SecureOn password of the client.
/// The length of the array is not 6.
/// is null.
/// is null.
/// An asynchronous which sends a Wake On LAN signal (magic packet) to a client.
public static Task SendWolAsync(this IPAddress target, byte[] macAddress, SecureOnPassword password)
{
return Net.MagicPacket.SendAsync(new IPEndPoint(target, DefaultWolPort), macAddress, password);
}
/// Sends a Wake On LAN signal (magic packet) to a client.
/// Destination .
/// The MAC address of the client.
/// The length of the is not 6.
/// is null.
/// An asynchronous which sends a Wake On LAN signal (magic packet) to a client.
public static Task SendWolAsync(this IPAddress target, PhysicalAddress macAddress) => target.SendWolAsync(macAddress, null);
/// Sends a Wake On LAN signal (magic packet) to a client.
/// Destination .
/// The MAC address of the client.
/// The SecureOn password of the client.
/// The length of the is not 6.
/// is null.
/// is null.
/// An asynchronous which sends a Wake On LAN signal (magic packet) to a client.
public static Task SendWolAsync(this IPAddress target, PhysicalAddress macAddress, SecureOnPassword password)
{
return Net.MagicPacket.SendAsync(new IPEndPoint(target, DefaultWolPort), macAddress, password);
}
#endregion
#region ARP
/// Sends a request via ARP to resolve an IP address to aphysical address. If the physical address is already cached, it's cached value is returned.
/// Destination .
/// An asynchronous which sends an ARP request.
public static Task SendArpRequestAsync(this IPAddress destination) => ArpRequest.SendAsync(destination);
#endregion
#endregion
}
}