0

Is it possible to send a wake on LAN command to a computer on a local network from a browser (no server side code). I have full control of the network. I would like to do it from a browser running on a tablet via wifi to a wired computer on the same LAN. I found some Node.JS JavaScript code: https://github.com/agnat/node_wake_on_lan/blob/master/wake_on_lan.js but I don't know if it will work from a browser.

Type955
  • 11
  • 1
  • 4

4 Answers4

2

You need some form of interface between the system calls that would dispatch a 'magic packet' and your Javascript. It seems to me you wouldn't be able to do this without some form of backend witchcraft which is able to use system calls. Javascript, in my experience, is limited to performing things on the client side and being able to talk to, but not control, the server side.

But then again, I'm not a web developer. My limited web experience tells me that you need something to talk to your operating system, which will ultimately send the WoL magic packet.

Zulukas
  • 1,180
  • 1
  • 15
  • 35
2

No, you can't.

The WoL needs to send a UDP broadcast package to the LAN. But browsers don't expose any API for UDP packages.

You need either server-side coding or browser plugins. You can write your own plugin that uses udp api.

ykaragol
  • 6,139
  • 3
  • 29
  • 56
  • Is there a way to break out of the sandbox of the browser and run an executable? – Type955 May 27 '16 at 20:40
  • @Type955 You would probably have to get the user to install a browser extension for it. On Windows you might be able to do it using Active X. – Barmar May 27 '16 at 20:58
  • 1
    @Type955 Yes, it's called [Native Messaging](https://developer.chrome.com/extensions/nativeMessaging). However, you said "running on a tablet", which depending on your definition of a tablet may not support extensions at all. – Xan May 27 '16 at 21:12
2

Nodejs is specifically for writing server side code. you can not do this without a server. You can however buy a small computer like a raspberry pi to be your server.

You will have to:

  • Buy a small simple computer like a raspberry pi or something similar.(this computer needs to be turned on all the time though)
  • Install node on it.
  • Write some javascript for the raspberry to take commands from the internet (like a browser extension) that can then send a local "magic packet" to the computer you want to wake up.
  • Then make a client program. like a browser extension or an android app that can send http stuff to your server(raspberry pi).

For writing the server code you can use https://www.npmjs.com/package/node-wol which is a node library.

Bitterbaam
  • 36
  • 4
0

Node is Server-side based, altought it uses Javascript Runtime Environment, it won't let you run something you wouldn't have permission to.

ZuLukas is pretty right. You can't do that with plain JavaScript code. You might find something right here: https://github.com/hypery2k/cordova-wol-plugin I bet it would be your best try without much effort.

You'll need to learn PhoneGap, then you'd build a Hybrid application. But, NOTICE that: JavaScript can't do that. Altough you'll code javascript to do it, it'll call native resources, and won't run in browser environment

Leonardo Lana
  • 590
  • 1
  • 4
  • 13