本文整理汇总了C#中System.Net.NetworkInformation.PhysicalAddress.GetAddressBytes方法的典型用法代码示例。如果您正苦于以下问题:C# PhysicalAddress.GetAddressBytes方法的具体用法?C# PhysicalAddress.GetAddressBytes怎么用?C# PhysicalAddress.GetAddressBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.NetworkInformation.PhysicalAddress
的用法示例。
在下文中一共展示了PhysicalAddress.GetAddressBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BroadcastMagicPacket
private static void BroadcastMagicPacket(PhysicalAddress physicalAddress, IPAddress broadcastIPAddress)
{
if (physicalAddress == null) throw new ArgumentNullException(nameof(physicalAddress));
var physicalAddressBytes = physicalAddress.GetAddressBytes();
var packet = new byte[17 * 6];
for (var i = 0; i < 6; i++)
{
packet[i] = 0xFF;
}
for (var i = 1; i <= 16; i++)
{
for (var j = 0; j < 6; j++)
{
packet[i * 6 + j] = physicalAddressBytes[j];
}
}
using (var client = new UdpClient())
{
client.Connect(broadcastIPAddress ?? IPAddress.Broadcast, 40000);
client.Send(packet, packet.Length);
}
}
示例2: MacRule
public MacRule(PacketStatus ps, PhysicalAddress mac, Direction direction, bool log, bool notify)
{
this.ps = ps;
this.mac = mac.GetAddressBytes();
this.direction = direction;
this.log = log;
this.notify = notify;
}
示例3: PrintMACAddress
/// <summary>
/// Creates a string from a Physical address in the format "xx:xx:xx:xx:xx:xx"
/// </summary>
/// <param name="address">
/// A <see cref="PhysicalAddress"/>
/// </param>
/// <returns>
/// A <see cref="System.String"/>
/// </returns>
public static string PrintMACAddress(PhysicalAddress address) {
byte[] bytes = address.GetAddressBytes();
string output = "";
for (int i = 0; i < bytes.Length; i++) {
output += bytes[i].ToString("x").PadLeft(2, '0') + ":";
}
return output.TrimEnd(':');
}
示例4: Send
/// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
/// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
/// <param name="macAddress">The MAC address of the designated client.</param>
/// <param name="password">The SecureOn password of the client.</param>
/// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
/// <exception cref="SocketException">An error occurred when accessing the socket. See Remarks section of <see cref="UdpClient.Send(byte[], int, IPEndPoint)"/> for more information.</exception>
public static void Send(IPEndPoint target, PhysicalAddress macAddress, SecureOnPassword password)
{
if (macAddress == null)
throw new ArgumentNullException(nameof(macAddress));
byte[] passwordBuffer = password?.GetPasswordBytes();
byte[] packet = GetWolPacket(macAddress.GetAddressBytes(), passwordBuffer);
SendPacket(target, packet);
}
示例5: FormatMacAddress
public static String FormatMacAddress(PhysicalAddress macAddress)
{
String str = String.Empty;
if (macAddress != null) {
str = BitConverter.ToString (macAddress.GetAddressBytes ()).Replace ('-', ':');
}
return str;
}
示例6: Send
/// <summary>
/// Sendet ein Wake-On-LAN-Signal an einen Client.
/// </summary>
/// <param name="target">Der Ziel-IPEndPoint.</param>
/// <param name="macAddress">Die MAC-Adresse des Clients.</param>
/// <exception cref="System.ArgumentNullException">macAddress ist null.</exception>
/// <exception cref="System.Net.Sockets.SocketException">Fehler beim Zugriff auf den Socket. Weitere Informationen finden Sie im Abschnitt "Hinweise".</exception>
public static void Send(IPEndPoint target, PhysicalAddress macAddress)
{
if (macAddress == null)
throw new ArgumentNullException("macAddress");
byte[] packet = GetWolPacket(macAddress.GetAddressBytes());
SendPacket(target, packet);
}
示例7: SendAsync
/// <summary>
/// Sendet ein Wake-On-LAN-Signal an einen Client.
/// </summary>
/// <param name="target">Der Ziel-IPEndPoint.</param>
/// <param name="macAddress">Die MAC-Adresse des Clients.</param>
/// <param name="password">Das SecureOn-Passwort des Clients.</param>
/// <exception cref="System.ArgumentNullException">macAddress ist null.</exception>
/// <exception cref="System.ArgumentNullException">password ist null.</exception>
/// <returns>Ein asynchroner Task, welcher ein Wake-On-LAN-Signal an einen Client sendet.</returns>
public static Task SendAsync(IPEndPoint target, PhysicalAddress macAddress, SecureOnPassword password)
{
if (target == null)
throw new ArgumentNullException("target");
if (macAddress == null)
throw new ArgumentNullException("macAddress");
if (password == null)
throw new ArgumentNullException("password");
var passwordBuffer = password.GetPasswordBytes();
var p = GetWolPacket(macAddress.GetAddressBytes(), passwordBuffer);
return SendPacketAsync(target, p);
}
示例8: MacAddrConvertable
public MacAddrConvertable(PhysicalAddress Mac)
: this(Mac.GetAddressBytes())
{
}
示例9: Pair
public override bool Pair(PhysicalAddress master)
{
var transfered = 0;
var host = master.GetAddressBytes();
byte[] buffer =
{
0x13, host[5], host[4], host[3], host[2], host[1], host[0], 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Buffer.BlockCopy(GlobalConfiguration.Instance.BdLink, 0, buffer, 7,
GlobalConfiguration.Instance.BdLink.Length);
if (SendTransfer(UsbHidRequestType.HostToDevice, UsbHidRequest.SetReport, 0x0313, buffer, ref transfered))
{
HostAddress = master;
Log.DebugFormat("++ Paired DS4 [{0}] To BTH Dongle [{1}]", DeviceAddress.AsFriendlyName(), HostAddress.AsFriendlyName());
return true;
}
Log.DebugFormat("++ Pair Failed [{0}]", DeviceAddress.AsFriendlyName());
return false;
}
示例10: Pair
/// <summary>
/// Pairs the current device to the provided Bluetooth host.
/// </summary>
/// <param name="master">The MAC address of the host.</param>
/// <returns>True on success, false otherwise.</returns>
public override bool Pair(PhysicalAddress master)
{
var transfered = 0;
var host = master.GetAddressBytes();
byte[] buffer = { 0x00, 0x00, host[0], host[1], host[2], host[3], host[4], host[5] };
if (!SendTransfer(UsbHidRequestType.HostToDevice, UsbHidRequest.SetReport, 0x03F5, buffer, ref transfered))
return false;
HostAddress = master;
return true;
}
示例11: GetMacStrFromPhysical
static string GetMacStrFromPhysical(PhysicalAddress pa)
{
byte[] macbyte = pa.GetAddressBytes();
string pastr = string.Format("{0:X2}{1:X2}{2:X2}{3:X2}{4:X2}{5:X2}", macbyte[0], macbyte[1], macbyte[2], macbyte[3], macbyte[4], macbyte[5]);
return pastr;
}
示例12: FormatMacAddress
public string FormatMacAddress(PhysicalAddress Input)
{
string Output = "";
byte[] bytes = Input.GetAddressBytes();
for (int i = 0; i < bytes.Length; i++)
{
// Display the physical address in hexadecimal.
Output += bytes[i].ToString("X2");
// Insert a hyphen after each byte, unless we are at the end of the
// address.
if (i != bytes.Length)
{
Output += ":";
}
}
return Output.Trim(':');
}
示例13: SetOtherMac
public void SetOtherMac(PhysicalAddress mac)
{
lock (padlock)
{
theirMac = mac.GetAddressBytes();
}
}
示例14: GenerateTimeBasedUUID
/**
* Method for generating time based UUIDs.
*
* @param addr Hardware address (802.1) to use for generating
* spatially unique part of UUID. If system has more than one NIC,
* any address is usable. If no NIC is available (or its address
* not accessible; often the case with java apps), a randomly
* generated broadcast address is acceptable. If so, use the
* alternative method that takes no arguments.
*
* @return UUID generated using time based method
*/
public UUID GenerateTimeBasedUUID(PhysicalAddress addr)
{
byte[] contents = new byte[16];
addr.GetAddressBytes().CopyTo(contents, 10);
lock (mTimerLock)
{
if (mTimer == null)
{
mTimer = new UUIDTimer(GetRandomNumberGenerator());
}
mTimer.GetTimestamp(contents);
}
return new UUID(UUID.TYPE_TIME_BASED, contents);
}
示例15: GetCommandPacket
//Build the command packet in bytes according to the value of each field
public static byte[] GetCommandPacket(SimulatorCommand sCommand, PhysicalAddress destMAC = null)
{
//If the command packet is for local NIC, we should set the MAC field to all 0
//If the command packet is for remote NIC, we should set the MAC field to remote MAC address
byte cmdByte = 0x00;
byte[] macInBytes = null;
switch (sCommand)
{
case SimulatorCommand.LoseLocalConnection:
cmdByte = BuildCommandByte((byte)NESNICLocation.Local, (byte)NESCommand.Lose);
macInBytes = localUsedMac;
break;
case SimulatorCommand.RestoreLocalConnection:
cmdByte = BuildCommandByte((byte)NESNICLocation.Local, (byte)NESCommand.Restore);
macInBytes = localUsedMac;
break;
case SimulatorCommand.LoseRemoteConnection:
cmdByte = BuildCommandByte((byte)NESNICLocation.Remote, (byte)NESCommand.Lose);
if (destMAC != null)
macInBytes = destMAC.GetAddressBytes();
break;
case SimulatorCommand.RestoreRemoteConnection:
cmdByte = BuildCommandByte((byte)NESNICLocation.Remote, (byte)NESCommand.Restore);
if (destMAC != null)
macInBytes = destMAC.GetAddressBytes();
break;
default:
break;
}
if (cmdByte == paddingByte || macInBytes == null)
return null;
int packetLength = guid.Length + 2 + macInBytes.Length; //The Length of Command Packet = GUID(16) + paddingByte(1) + commandByte(1) + MAC(1)
int curIdx = 0;
byte[] res = new byte[packetLength];
Array.Copy(guid, res, guid.Length);
curIdx = guid.Length;
res[curIdx++] = paddingByte;
res[curIdx++] = cmdByte;
Array.Copy(macInBytes, 0, res, curIdx, macInBytes.Length);
curIdx += macInBytes.Length;
return res;
}