kbr / fritzconnection

Python-Tool to communicate with the AVM Fritz!Box by the TR-064 protocol and the AHA-HTTP-Interface
MIT License
303 stars 59 forks source link

#148 Wake on LAN via CLI #149

Open samba2 opened 2 years ago

samba2 commented 2 years ago

see issue #148 for details

kbr commented 2 years ago

FritzHosts provides get_wakeonlan_status and set_wakeonlan_status methods for the "AutoWakeOnLAN" feature of the router. Currently I have no NAS for checking – but may be that already satisfies (at least partially) your use-case?

samba2 commented 2 years ago

No, for clarity I took a screen shot:

image

the API calls used in get_wakeonlan_status and set_wakeonlan_status are for the left hand checkbox which allows you (appropriate port forwarding + dyndns provided) to wake up an internal host via Wake on LAN (WOL) magic packet. What the Fritzbox does: in the moment it receives a packet from the internet which is destined to the host, than the Fritzbox sends the WOL magic packet to the host to wake it up.

The code in this PR is about the righthand side. It simply is for "given I am in the local network I'd like to wakeup this host. If the host to be woken up and the waking up host are in the same layer 2 network (so e.g. both on LAN or both on wifi) also third party programs to broadcast the magic packet could be used. However, in my situation the host to be woken up (my NAS) is in the LAN and the waking up host is on wifi. Since the magic packet is not routed the only method to wake the NAS up is to use this "Computer starten" functionality of the Fritzbox which thankfully is exposed via the API.

samba2 commented 1 month ago

@kbr sorry for the slight delay 🙂 I've worked on your feedback and also ran the code locally:

Successfully wakes up my diskstation:

fritzwol -i 192.168.178.1 -p *** diskstation

fritzconnection v1.9.1
FRITZ!Box 7530 at http://192.168.178.1
FRITZ!OS: 7.57

Waking up host 'diskstation'...
Done

Gives error when hostname is not known at Fritzbox:

fritzwol -i 192.168.178.1 -p *** foo

fritzconnection v1.9.1
FRITZ!Box 7530 at http://192.168.178.1
FRITZ!OS: 7.57

Waking up host 'foo'...
Host 'foo' is unknown at Fritzbox.
samba2 commented 1 month ago

If you feel like shaping the comments a bit more, please go ahead.