{"id":28386,"date":"2017-10-15T17:07:49","date_gmt":"2017-10-15T11:37:49","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=28386"},"modified":"2017-10-15T17:07:49","modified_gmt":"2017-10-15T11:37:49","slug":"program-remotely-power-pc-program-remotely-power-pc-internet-using-wake-lan-protocol-internet-using-wake-lan-protocol","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/program-remotely-power-pc-program-remotely-power-pc-internet-using-wake-lan-protocol-internet-using-wake-lan-protocol\/","title":{"rendered":"Program to remotely Power On a PC over the internet using the Wake-on-LAN protocol."},"content":{"rendered":"<p>Wake-on-LAN (WoL) is an Ethernet or token ring computer networking standard that allows a computer to be turned on or awakened by a network message.<\/p>\n<ul>\n<li>The message is usually sent to the target computer by a program executed on a device connected to the same local area network, such as a smartphone.<\/li>\n<li>It is also possible to initiate the message from another network by using subnet directed broadcasts or a WOL gateway service.<\/li>\n<li>Equivalent terms include wake on WAN, remote wake-up, power on by LAN, power up by LAN, resume by LAN, resume on LAN and wake up on LAN.<\/li>\n<\/ul>\n<p><strong>Principle of operation<\/strong><\/p>\n<ul>\n<li>Wake-on-LAN (\u201cWOL\u201d) is implemented using a specially designed packet called a magic packet, which is sent to all computers in a network, among them the computer to be awakened.<\/li>\n<li>The magic packet contains the MAC address of the destination computer, an identifying number built into each network interface card (\u201cNIC\u201d) or other ethernet device in a computer, that enables it to be uniquely recognized and addressed on a network.<\/li>\n<li>Powered-down or turned off computers capable of Wake-on-LAN will contain network devices able to \u201clisten\u201d to incoming packets in low-power mode while the system is powered down.<\/li>\n<li>If a magic packet is received that is directed to the device\u2019s MAC address, the NIC signals the computer\u2019s power supply or motherboard to initiate system wake-up, much in the same way as pressing the power button would do.<\/li>\n<li>The magic packet is sent on the data link layer (layer 2 in the OSI model) and when sent, is broadcast to all attached devices on a given network, using the network broadcast address; the IP-address (layer 3 in the OSI model) is not used.[ad type=&#8221;banner&#8221;]<\/li>\n<\/ul>\n<p>In order for Wake-on-LAN to work, parts of the network interface need to stay on. This consumes a small amount of standby power, much less than normal operating power. Disabling wake-on-LAN when not needed, can therefore very slightly reduce power consumption on computers that are switched off but still plugged into a power socket.<\/p>\n<p><strong>Magic Packet Structure<\/strong><br \/>\nThe magic packet is a broadcast frame containing anywhere within its payload 6 bytes of all 255 (FF FF FF FF FF FF in hexadecimal), followed by sixteen repetitions of the target computer\u2019s 48-bit MAC address, for a total of 102 bytes.<br \/>\nSince the magic packet is only scanned for the string above, and not actually parsed by a full protocol stack, it may be sent as any network- and transport-layer protocol, although it is typically sent as a UDP datagram to port 0, 7 or 9, or directly over Ethernet as EtherType 0x0842.<\/p>\n<p><strong>A standard magic packet has the following basic limitations:<\/strong><\/p>\n<ol>\n<li>Requires destination computer MAC address (also may require a SecureOn password).<\/li>\n<li>Does not provide a delivery confirmation.<\/li>\n<li>May not work outside of the local network.<\/li>\n<li>Requires hardware support of Wake-On-LAN on destination computer.<\/li>\n<li>Most 802.11 wireless interfaces do not maintain a link in low power states and cannot receive a magic packet.<\/li>\n<\/ol>\n<p>The Wake-on-LAN implementation is designed to be very simple and to be quickly processed by the circuitry present on the network interface card with minimal power requirement. Because Wake-on-LAN operates below the IP protocol layer the MAC address is required and makes IP addresses and DNS names meaningless.[ad type=&#8221;banner&#8221;]\n<div>\u00a0C programming:<\/div>\n<div>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-c code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-c code-embed-code\">\/\/ C program to remotely Power On a PC over the<br\/>\/\/ internet using the Wake-on-LAN protocol.<br\/>#include &lt;stdio.h&gt;<br\/>#include &lt;stdlib.h&gt;<br\/>#include &lt;unistd.h&gt;<br\/>#include &lt;sys\/socket.h&gt;<br\/>#include &lt;netinet\/in.h&gt;<br\/>#include &lt;arpa\/inet.h&gt;<br\/>#include &lt;string.h&gt;<br\/>#include &lt;sys\/types.h&gt;<br\/> <br\/>int main()<br\/>{<br\/>    int i;<br\/>    unsigned char toSend[102],mac[6];<br\/>    struct sockaddr_in udpClient, udpServer;<br\/>    int broadcast = 1 ;<br\/> <br\/>    \/\/ UDP Socket creation<br\/>    int udpSocket = socket(AF_INET, SOCK_DGRAM, 0);<br\/> <br\/>    \/\/ Manipulating the Socket<br\/>    if (setsockopt(udpSocket, SOL_SOCKET, SO_BROADCAST,<br\/>                  &amp;broadcast, sizeof broadcast) == -1)<br\/>    {<br\/>        perror(&quot;setsockopt (SO_BROADCAST)&quot;);<br\/>        exit(EXIT_FAILURE);<br\/>    }<br\/>    udpClient.sin_family = AF_INET;<br\/>    udpClient.sin_addr.s_addr = INADDR_ANY;<br\/>    udpClient.sin_port = 0;<br\/> <br\/>    \/\/Binding the socket<br\/>    bind(udpSocket, (struct sockaddr*)&amp;udpClient, sizeof(udpClient));<br\/> <br\/>    for (i=0; i&lt;6; i++)<br\/>        toSend[i] = 0xFF;<br\/> <br\/>    \/\/ Let the MAC Address be ab:cd:ef:gh:ij:kl<br\/>    mac[0] = 0xab;  \/\/ 1st octet of the MAC Address<br\/>    mac[1] = 0xcd;  \/\/ 2nd octet of the MAC Address<br\/>    mac[2] = 0xef;  \/\/ 3rd octet of the MAC Address<br\/>    mac[3] = 0xgh;  \/\/ 4th octet of the MAC Address<br\/>    mac[4] = 0xij;  \/\/ 5th octet of the MAC Address<br\/>    mac[5] = 0xkl;  \/\/ 6th octet of the MAC Address<br\/> <br\/>    for (i=1; i&lt;=16; i++)<br\/>        memcpy(&amp;toSend[i*6], &amp;mac, 6*sizeof(unsigned char));<br\/> <br\/>    udpServer.sin_family = AF_INET;<br\/> <br\/>    \/\/ Braodcast address<br\/>    udpServer.sin_addr.s_addr = inet_addr(&quot;10.89.255.255&quot;);<br\/>    udpServer.sin_port = htons(9);<br\/> <br\/>    sendto(udpSocket, &amp;toSend, sizeof(unsigned char) * 102, 0,<br\/>             (struct sockaddr*)&amp;udpServer, sizeof(udpServer));<br\/>    return 0;<br\/>}<\/code><\/pre> <\/div>\n<p>Output:<\/p>\n<pre>This program will power on the switched-off PC\r\nwhose MAC Address is used in this program (the \r\nPC and the Host computer must be connected over\r\nLAN).<\/pre>\n<\/div>\n[ad type=&#8221;banner&#8221;]\n","protected":false},"excerpt":{"rendered":"<p>Program to remotely Power On a PC over the internet using the Wake-on &#8211; LAN protocol &#8211; Wake-on-LAN (WoL) is an Ethernet or or token ring computer networking<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82277,71771],"tags":[82882,82880,82881,82884,82879,82883,82886,82885],"class_list":["post-28386","post","type-post","status-publish","format-standard","hentry","category-computer-networks","category-cs-subjects","tag-how-to-wake-on-lan","tag-wake-on-lan-command","tag-wake-on-lan-magic-packet","tag-wake-on-lan-online","tag-wake-on-lan-software","tag-wake-on-lan-windows","tag-wake-on-lan-windows-10","tag-wake-on-lan-windows-7"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/28386","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=28386"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/28386\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=28386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=28386"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=28386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}