Skip to content

Instantly share code, notes, and snippets.

@Hermann-SW
Created July 14, 2023 10:13
Show Gist options
  • Save Hermann-SW/d1dfba93834702dca40031e1e9532638 to your computer and use it in GitHub Desktop.
Save Hermann-SW/d1dfba93834702dca40031e1e9532638 to your computer and use it in GitHub Desktop.
minimal nodejs code to power on wakeonlan enabled PC with given mac address
// eslinted; send wakeonlan magic packet for mac address defined in m
//
const m = Buffer.from([0x9c, 0x6b, 0x00, 0x15, 0xbd, 0xc2]);
const p = Buffer.concat([Buffer.alloc(6,0xff),m,m,m,m,m,m,m,m,m,m,m,m,m,m,m,m]);
const sock = require('dgram').createSocket('udp4').on('listening', function() {
sock.setBroadcast(true);
sock.send(p, 0, p.length, 9, '255.255.255.255', function() {
sock.close();
});
}).bind();
@Jibun-no-Kage
Copy link

I have found it of benefit to send magic packets 3 times, some times the first or second packet is lost, dropped, ignored, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment