1

Could you guys help me out with setting up a WOL setting? There's a catch. I've googled a bit and found solutions but I want something more delicate. Google suggests that I remotely execute a bash script waking the target computer. I want to make it simpler. For example, by sending magic packet to the Pi computer (which is already running, of course) which will be used as an event trigger to wake another PC. Is it possible to achieve?

I am running a Raspbery Pi OS June 2021.

1
  • 1
    okay, I've managed to wake up the target PC with this command: socat -u udp-recvfrom:10,fork exec:scripts/pi-wol.sh I figured it out a little. The package loop happens when I sent a magic packet to the broadcast address which is 192.168.1.255. If I send it straight to the target pc IP, it works perfectly. Now, I tried adding this line to end of the /etc/rc.local, but it doesn't seem to work at startup. How do I make it so socat starts listening for packets at startup?
    – magrega
    Commented Sep 5, 2021 at 19:30

2 Answers 2

2

You could use tcpdump or wireshark to monitor the network interface on the Pi and set up a filter for the magic packet of your choice. For example, for a ping packet that could be:

tcpdump -i eth0 icmp and icmp[icmptype]=icmp-echo

Pipe the output of tcpdump to a script which wakes up the target computer on any new input:

while read line; do wakeonlan <mac address>; done

and the target computer should wake up every time someone pings your Pi.

5
  • I get the general idea of what you are trying to suggest but I am rather new to this whole linux and raspberry pi thing so making scripts is a little out of my league here. I would appreciate if you could elaborate on the second part a little.
    – magrega
    Commented Sep 1, 2021 at 9:25
  • @magrega Did you get a solution you mention in the question (with a bash script) running? Perhaps you should start with that, a tutorial will teach you how to write scripts and will be a useful test step for the final solution. Commented Sep 1, 2021 at 11:07
  • okay, I've managed to wake up the target PC with this command: socat -u udp-recvfrom:10,fork exec:scripts/pi-wol.sh I figured it out a little. The package loop happens when I sent a magic packet to the broadcast address which is 192.168.1.255. If I send it straight to the target pc IP, it works perfectly. Now, I tried adding this line to end of the /etc/rc.local, but it doesn't seem to work at startup. How do I make it so socat starts listening for packets at startup?
    – magrega
    Commented Sep 5, 2021 at 19:41
  • @magrega Make it a systemd service instead of rc.local. Then you'll be able to schedule it after the networking service. Commented Sep 6, 2021 at 6:40
  • How do I make it startup with the system without me logging in?
    – magrega
    Commented Sep 6, 2021 at 8:19
1

Okay, after some days of struggle and figuring this stuff out, I've finally made it happen. What I did was:

  1. wrote a bash script that sends a magic packet with the mac address of the target pc to the local IP-address with a port of that pc.
#!/bin/bash
sudo wakeonlan -i 12.121.12.12 -p 99 1a:2b:3c:4d:5e:6f
  1. installed socat
  2. figured out the command which I need to make it listen constantly for the packet on the specified port: sudo socat -u udp-recvfrom:10,fork exec:scripts/pi-wol.sh
  3. added it as a systemd service by using this guide. Had to move the script to /usr/bin, so it could be started at startup by root. Eventually the service file looked like this:
[Unit]
Description=Socat WOL

[Service]
Type=simple
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=socat-wol

ExecStart=/usr/bin/socat -u udp-recvfrom:10,fork exec:/usr/bin/pi-wol.sh

[Install]
WantedBy=multi-user.target

What happens now is when I send a magic packet to my RPi through internet (don't forget to port forward sent packets to your local Pi) RPi recieves it and the script is triggered - it sends a wol-packet to my target pc waking it up from turned off state.

I spent 4 days of constant googling and getting on people's nerves to get here and now I see it all could be done in 4 simple steps which take 15 minutes or less.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.