[HN Gopher] Waking My Computer from Afar
___________________________________________________________________
Waking My Computer from Afar
Author : ingve
Score : 31 points
Date : 2024-03-18 14:05 UTC (1 days ago)
(HTM) web link (bernsteinbear.com)
(TXT) w3m dump (bernsteinbear.com)
| muxator wrote:
| No big deal, but instead of running "wakeonlan" as a subprocess:
| import subprocess [...] result =
| subprocess.run(["wakeonlan", "MY:MA:CA:DD:RE:SS"],
| capture_output=True)
|
| The magic packet could be built and broadcast in pure python,
| without introducing a dependency on an external binary.
|
| For example, one could take inspiration from the code at
| https://github.com/remcohaszing/pywakeonlan/blob/main/wakeon...
| tekknolagi wrote:
| I am very lazy :)
| tekknolagi wrote:
| (Though, to be clear, I do like the idea of doing it purely
| in Python!)
| iam-TJ wrote:
| I wrote a pure bash shell version for use on my IPv6-only
| networks. I initially wanted to make pure POSIX sh but the ease
| of being able to use ${param,,} and more importantly
| /dev/udp/$IP/$PORT makes bash more suitable for the use-case.
| #!/usr/bin/env bash
| config_sys="${config_sys:-/etc/wol}"
| config_user="${config_user:=$HOME/.config/wol}"
| PORT="${PORT:-9999}" cat <<EOF WoL Wake-On-LAN
| Magic Packet transmitter Copyright 2023 Tj
| <hacker@iam.tj> Licensed on the terms of the GNU General
| Public Licence version 3. EOF ls() {
| shopt -s nullglob for f in $@; do
| printf "%s\n" "${f##*/}" done } if
| [ -z "$1" ]; then cat <<-EOF Please
| specify the hostname. Currently defined: System
| ($config_sys/): $(ls "$config_sys/*" 2>/dev/null)
| User ($config_user/): $(ls "$config_user/*" 2>/dev/null)
| Config files should be named for the target host
| Content is shell variable definitions Required: IP=
| and MAC= Optional: PORT= (default is ${PORT})
| E.g: MAC="60:45:cb:9f:42:fb"
| IP="fddc:7e00:e001:ee80::2" EOF exit 1
| fi for conf in "$config_sys" "$config_user"; do
| if [[ -r "$conf/$1" ]]; then . "$conf/$1"
| # don't break; allow user override fi done
| if [[ -z "$IP" ]] || [[ -z "$MAC" ]]; then >&2
| printf "Error: required configuration missing IP='%s'
| MAC='%s'\n" "$IP" "$MAC" exit 2 fi
| target="/dev/udp/$IP/$PORT" hex2char() # $1 = 2 hex
| digits { case "${#1},${1,,}" in
| (2,*[!0-9a-f]*) return 2 ;; (2,*) printf
| '%b' "\x$1" ;; (*) return 1 ;;
| esac } make_payload() # $1 = Ethernet MAC
| address with ":" separators { IFS=":" read -r
| -a mac < <(echo "$1") for h in "${mac[@]}"; do
| magic="$magic$(hex2char "$h")" done
| payload="" ff="$(hex2char "ff")" for
| ((i=0; i < 6; i++)); do
| payload="${payload}${ff}" done for
| ((i=0; i < 16; i++)); do
| payload="${payload}${magic}" done }
| printf "Sending magic packet to %s (%s port %s [MAC %s])\n"
| "$1" "$IP" "$PORT" "$MAC" make_payload "$MAC"
| printf "%s" "$payload" > "$target" || printf "error: failed to
| send (error %s)\n" "$?"
| politelemon wrote:
| > I added the Pi to my Tailscale network (no, this is not an ad;
| just happy), which was pretty painless.
|
| I had a quick look at Tailscale and it seems to be a VPN network
| that you get to manage? So it's still a VPN just with convenience
| functions to make adding devices easy is that about right? Where
| does the DNS for this exist, is it on Tailscale's own servers.
| There must be some purpose to having to login. Does Tailscale
| also hold some connection open to figure out which devices are on
| or not.
|
| In a way this reminds me of AWS SSM Agent. I think it's talking
| to some central Amazon servers and I don't need to open a port on
| an EC2.
| zrail wrote:
| Tailscale is a mesh overlay network that uses Wireguard under
| the hood. Traffic moves peer to peer as much as possible. DNS
| happens locally (the special 100.100.100.100 address actually
| points at the tailscale daemon running on each machine, which
| already holds the name -> address mapping that MagicDNS needs
| to work).
|
| You login to Tailscale from each device in order for the
| central Tailscale control plane to authenticate the device and
| for it to distribute that device's public Wireguard key out to
| the rest of the mesh.
| CharlesW wrote:
| I haven't personally used this, but many folks on HN also
| like that there's an open-source, self-hosted implementation
| of the control server. https://github.com/juanfont/headscale
| angott wrote:
| Tailscale runs its own local DNS resolver on your computer at
| 100.100.100.100, if you have enabled that in settings. Your DNS
| queries don't go to any Tailscale servers. By default, the
| client simply forwards all queries to the system DNS resolver,
| providing some added conveniences like automatic DNS over HTTPS
| upgrade when available. Also, you don't really have to use
| Tailscale for DNS if you're comfortable reaching your devices
| using their 100.x.y.z IP address. See
| https://tailscale.com/kb/1081/magicdns for more details.
|
| And yes, Tailscale keeps a connection open to its servers to
| allow other devices to reach you when you're behind a firewall
| and direct connections can't be established.
| doctorhandshake wrote:
| This is my setup, without the GUI. I join the Tailscale network
| on my laptop, ssh into my pihole (slash homelab misc) pi, and run
| 'wol'. I also have the PC set to boot in the early hours (in
| BIOS) in case I'm away for a long time and accidentally pick
| 'shut down' instead of 'sleep' at some point.
| ranger_danger wrote:
| People shut down their computers?
|
| Are there places in the world where people have to actually care
| about the power consumption of their computer so much that this
| is a thing? Any examples?
| dist-epoch wrote:
| I know this is probably extremely surprising for you, but some
| people do the little things which help the environment even if
| it causes them mild inconvenience.
| GaryHak wrote:
| Putting my systems to sleep at night saves me EUR 400,- a
| year. Enough to buy a mini pc to watch the fortress.
| pohuing wrote:
| It takes 20 seconds to boot and it warms up my room if on. So
| why would I keep it on all the time. I turn it on when I use it
| and turn it off when I don't.
| tarxvf wrote:
| Many people with homelabs - or a NAS with a ton of disks -
| don't use it all that often and it can cost quite a bit in
| electricity over the course of a month. Or maybe they live in
| an apartment and prefer quiet over the noise of fans and disks.
| FridgeSeal wrote:
| Because it costs money to run and I'm not made of money? It
| might be cherish, but money I don't have to spend is even
| better. It's also better for the environment(!!) and I like my
| working space to be as quiet as possible.
| avh02 wrote:
| Some people live in places with rolling blackouts and the UPS
| doesn't last long enough, so easier to shutdown cleanly and
| power off the UPS so you're not constantly cycling the battery
| for no good reason.
| Jerrrry wrote:
| The only people who still consciously shut down their computers
| are precisely the kind to tell you exactly which tree they are
| so keen to save, and which molecule of water they avoided
| warming last winter.
| IshKebab wrote:
| My computer uses about 150W idle. The only people who leave
| that running 24/7 are those that a) enjoy ruining things for
| others, b) hate money, or c) are too stupid to realise how
| much power they're wasting.
| m463 wrote:
| I guess the answer is "it depends"
|
| with average california cost/kwh (.35)
|
| raspberry pi ~ $1/month
|
| 200w server ~ $50/month
|
| also, more time on _might_ mean more disk wear and greater
| chance of hardware failure. (there is probably some sort of
| heat shock, so leaving things on might be good too)
| leptons wrote:
| Your comment is shockingly out of touch, are you Elon Musk?
| Check out Mr. Billionaire over here, with money to throw away
| on idle computers.
|
| I live in California. Electricity _is not free_ , or even
| cheap.
|
| I have 4 computers. 1 out in the garage that's my "off-site"
| backup system, complete with LTO tape drive. It's also got an 8
| drive RAID10 array. I don't need it running 24/7. I need it on
| when I have a backup job for it to do, and off when I don't
| need it on.
|
| I have a workstation that I only use when I'm developing
| personal code. I don't need it running 24/7. It also has 8
| spinning disks, video card, and a massive CPU. It consumes
| about 300W of power, so that adds up.
|
| My laptop is off when I'm not using it, but even that I wake
| remotely from time to time when I'm out in the garage and need
| a file from it.
|
| I have 1 server that runs 24/7 and handles Plex, security
| cameras, and 6 virtual machines. It's a workhorse, but it's got
| a 65W CPU in it and barely uses the video card.
|
| My electric bill is $600/month in the summer months, mostly due
| to AC but I don't need to make it any worse by running 4
| computers continuously when I don't need to.
| stzsch wrote:
| I used a similar setup to reboot my home server remotely, with
| gpio pins instead of wakeonlan.
|
| I eventually replaced it with an aliexpress tuya pcie power
| switch. I just wish I'd gotten the zigbee version. Homeassistant
| with local tuya wifi devices is quite janky.
| aktuel wrote:
| And how is this better or easier than just setting up the port
| forwarding on the router?
| tekknolagi wrote:
| a) Come on, be kind
|
| b) I don't have to think about doing systems administration on
| the very resource-limited stripped-down OpenWRT device
|
| c) It's probably marginally more secure
| IshKebab wrote:
| Have you ever actually tried that? I have. It's _possible_ with
| some router, but IIRC I had to install some custom config file
| from some random site. Definitely wasn 't easy. I think with
| _most_ routers it isn 't possible at all.
|
| If you're imagining you just forward the port to your computers
| IP address... no that doesn't work. Because while your computer
| is asleep it doesn't _have_ an IP address. What you need to do
| is configure the router to forward broadcast packets to the
| local subnet. Something like that anyway, I can 't remember the
| exact details.
| wzdd wrote:
| I recently had a similar problem for my Linux-based desktop, but
| found that it didn't support wake on LAN. So instead I wired an
| ESP8266 to the ATX power pins on the motherboard (via an opto-
| isolator, in parallel with the actual switch so both could be
| used). Code on the esp8266, which connects to a network server,
| can then "depress" the power line for a configurable number of
| milliseconds.
|
| Apart from working on my PC, this is also quite nice as it gives
| you a way to force-power-off remotely if necessary.
| nick238 wrote:
| I converted an old system to a server, and the WOL was super
| unreliable (poor mobo support, crappy network, ??). Wound up
| getting a PiKVM setup for $100 + RPi5 (Geekworm KVM-A8 Kit
| "PCIe" Version) which works pretty well, if perhaps overkill.
| The "official" PiKVM hardware is a bit more expensive (~$300
| but also has a fancy steel case and HDMI passthrough)
|
| There's a BliKVM "card" which also looks interesting and I'd
| probably use if I did it again because I was trying to fit the
| card above the GPU and it took some modding.
| leptons wrote:
| I did something similar recently.
|
| I wanted to wake my laptop via wifi. There's no way to do it
| using WoL with the laptop's wifi card.
|
| For some reason the laptop's wifi card won't be powered during
| sleep or never responds to WoL packets, but the USB port is
| powered during sleep.
|
| I got an ESP32-S3 which has built-in USB. I cobbled together
| the examples from the ESP-IDF framework. Using one wifi example
| I got the ESP32 to detect WoL packets sent to it, and the other
| example was the USB HID example that acts like a mouse and
| moves the cursor around.
|
| So now I can send a WoL request to the ESP32, and it will then
| "move the mouse" and wake the laptop. It worked like a charm
| and only took me about 2 evenings to put together.
| scottlamb wrote:
| > Now, you might be wondering to yourself "Max, you said you
| weren't running as root. How are you binding to port 80?" Well,
| sudo setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/busybox. But you
| could also run on an unprivileged port like 8080.
|
| As you're launching from systemd anyway, I'd try something like
| `AmbientCapabilities=CAP_NET_BIND_SERVICE` in the unit file
| (caveat: untested). Then it's scoped to that unit, where it's (1)
| needed and (2) clear why it's needed. Instead of the busybox
| executable that (1) likely is used in a bunch of places where
| that's unneeded and (2) may get reinstalled by the package
| manager without this perm, quietly breaking your setup.
|
| systemd also supports binding the port for you, but afaict from a
| quick skim, Busybox httpd doesn't support accepting the socket
| from systemd, so that wouldn't be as easy a change.
| tekknolagi wrote:
| Oh, neat! Thanks. I didn't know about AmbientCapabilities.
| squarefoot wrote:
| This seems a use case where the smallest the better since the
| small system only has to close a contact according to a condition
| on the local network. This could also be done with a very small
| uC with Ethernet (example: Arduino and others + w5100 or
| compatible Ethernet chip; I'm not a fan of WiFi in these
| contexts). There is also a SSL library that can be used to run a
| minimal secure web server to host the magic button that would
| trigger the switch on through the gpio.
|
| https://www.arduino.cc/reference/en/libraries/ethernetwebser...
|
| Or it could employ some sort of port knocking on the uC+Eth board
| so that it wakes up the main system only when the right sequence
| is used. The advantage of using a uC, lower power draw aside, is
| that micro SD cards (and their sockets) are less reliable than
| internal flash.
| y04nn wrote:
| One solution that I use and like because it is reliable, is to
| change the BIOS to "Power On" after a power failure and use a
| smart plug to turn on the computer.
|
| So turning the smart plug on my phone on would start the
| computer. I use it for my backup server with a JBOD that is only
| turned on when I need it. You can also schedule on/off time on
| the app. And if you want to programmatically turn it on/off you
| can setup Home Assistant with the plug.
___________________________________________________________________
(page generated 2024-03-19 23:00 UTC)