C # network wake-up

Source: Internet
Author: User

What is network wake-up?

Network wake-up enables centralized network management. At any time, IT administrators in the network management center can remotely wake up a computer in sleep or shutdown state. With this function, IT administrators can complete the upgrade and other management tasks of all operating systems and applications when the network traffic is the minimum and the normal operation of the enterprise is the least affected after work.

 

To wake up a computer on the network, you must send a data packet in a different format than a common data packet. In addition, you must use the corresponding special software to generate the data packet. Magic Packet, developed by AMD, is widely used today. This software can generate special packets needed for network wakeup. The data package contains 6 consecutive bytes of "FF" and 16 consecutive MAC addresses. Although Magic Packet is only a technology developed and promoted by AMD, it is not an industry-recognized standard, but it is still supported by many Nic manufacturers. Therefore, many NICs with the network wake-up function can be compatible with it.

 

To wake up using the network, you must have:

 

1: software that can send wake-up frames to the network adapter.

2: Enable decoding of the "Wake-up frame" Nic. The NIC must also be able to obtain energy from the auxiliary power supply and send a "Wake-up signal" to the motherboard ". (Basically supported)

 

First, how to set the wake-up Machine

 

1. Set the NIC Driver attribute in Windows 7, for example, computer-Device Manager-

2. Run the ipconfig-all command to view the MAC address of the local Nic.

 

 

C # The Code is as follows:

Private IPEndPoint point; private UdpClient client = new UdpClient (); /*** method to wake up a remote machine ** @ param * The mac * IP * port udp message sending port of the machine to be awakened by MAC ** Abstract: the wake-up method provides the magic packet function for the NIC, that is, to send 6 FF messages in broadcast mode and add 16 byte arrays of the target MAC address **/private void wakeUp (string mac, int port, string ip) {byte [] magicBytes = getMagicPacket (mac); point = new IPEndPoint (IPAddress. parse (ip), port); // broadcast mode: Broadcast bandwidth 255.255 try {client. send (magicBytes, magicBytes. Length, point);} catch (SocketException e) {MessageBox. show (e. message );}} /// <summary> /// string to a hexadecimal byte array /// </summary> /// <param name = "hexString"> </param> // /<returns> </returns> public static byte [] strToHexByte (string hexString) {hexString = hexString. replace ("", ""); if (hexString. length % 2 )! = 0) hexString + = ""; byte [] returnBytes = new byte [hexString. length/2]; for (int I = 0; I <returnBytes. length; I ++) returnBytes [I] = Convert. toByte (hexString. substring (I * 2, 2), 16); return returnBytes ;} /// <summary> /// assemble the MAC magic package /// </summary> /// <param name = "hexString"> </param> /// <returns> </returns> public static byte [] getMagicPacket (string macString) {byte [] returnBytes = new byte [102]; string commandString = "ffffffffff"; for (int I = 0; I <6; I ++) returnBytes [I] = Convert. toByte (commandString. substring (I * 2, 2), 16); byte [] macBytes = strToHexByte (macString); for (int I = 6; I <102; I ++) {returnBytes [I] = macBytes [I % 6];} return returnBytes ;}

 

Of course, this is only implemented in the LAN. If you want to implement it in the wide area network, you still need to map the vro and so on. This article will not discuss it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.