当前位置: 首页>>代码示例>>C#>>正文


C# PhysicalAddress.GetAddressBytes方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:shaftware,项目名称:NetMagic,代码行数:27,代码来源:Program.cs

示例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;
 }
开发者ID:prashanthbc,项目名称:firebwall,代码行数:8,代码来源:fireBwallModule.cs

示例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(':');
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:18,代码来源:HexPrinter.cs

示例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);
        }
开发者ID:nikeee,项目名称:wake-on-lan,代码行数:15,代码来源:SendWol.cs

示例5: FormatMacAddress

        public static String FormatMacAddress(PhysicalAddress macAddress)
        {
            String str = String.Empty;

            if (macAddress != null) {
                str = BitConverter.ToString (macAddress.GetAddressBytes ()).Replace ('-', ':');
            }

            return str;
        }
开发者ID:orion75,项目名称:UbntTools,代码行数:10,代码来源:Utils.cs

示例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);
        }
开发者ID:MuhammadWaqar,项目名称:wake-on-lan,代码行数:15,代码来源:SendWol.cs

示例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);
        }
开发者ID:MuhammadWaqar,项目名称:wake-on-lan,代码行数:22,代码来源:SendWol.cs

示例8: MacAddrConvertable

 public MacAddrConvertable(PhysicalAddress Mac)
     : this(Mac.GetAddressBytes())
 {
 }
开发者ID:MartinNuc,项目名称:AdminRequest,代码行数:4,代码来源:MacAddrConvertable.cs

示例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;
        }
开发者ID:theczorn,项目名称:ScpToolkit,代码行数:24,代码来源:UsbDs4.cs

示例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;
        }
开发者ID:CheesyKek,项目名称:ScpToolkit,代码行数:18,代码来源:UsbDs3.cs

示例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;
 }
开发者ID:kostaslamda,项目名称:win-xenguestagent,代码行数:6,代码来源:NetInfo.cs

示例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(':');
 }
开发者ID:fredefl,项目名称:Computer-Info,代码行数:17,代码来源:ComputerInfoClass.cs

示例13: SetOtherMac

 public void SetOtherMac(PhysicalAddress mac)
 {
     lock (padlock)
     {
         theirMac = mac.GetAddressBytes();
     }
 }
开发者ID:hatRiot,项目名称:fireBwall,代码行数:7,代码来源:SimpleMacEncryption.cs

示例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);
        }
开发者ID:tlaukkan,项目名称:mono-uuid-generator,代码行数:30,代码来源:UUIDGenerator.cs

示例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;
            }
开发者ID:JessieF,项目名称:ProtocolTestFramework,代码行数:46,代码来源:NetworkEventSimulator.cs


注:本文中的System.Net.NetworkInformation.PhysicalAddress.GetAddressBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。