nbanb / fbx-delta-nba_bash_api.sh

Access FreeboxOS API from bash
Other
3 stars 1 forks source link

[Feature request] Add support for Wake On Lan endpoint #2

Open na-ji opened 4 months ago

na-ji commented 4 months ago

Hello,

This is a feature request: would it be possible to support the Wake on Lan endpoint, please? This would allow using the bash script to automatically start devices, and schedule them with cron. I didn't find the documentation of this endpoint on the internal documentation available on mafreebox.freebox.fr, but I did find it here: https://dev.freebox.fr/sdk/os/lan/ I tested on Insomnia and it works well.

What do you think?

nbanb commented 2 days ago

Hi

Sorry for my late answer. OK, it seems to be a good idea.

I did find the documenation in the developper section of mafreebox.freebox.fr on : API List > Configuration > LAN Browser > Wake On LAN

For the moment (until it's been officially added to the library), as it's a simple instruction you can use machine_1 to wake up machine_2 from freebox API :

machine_2 mac address ; 06:c2:93:c3:0b:df machine_2 password :

user@machine_1 $ add_freebox_api lan/wol/pub '{"mac":"06:c2:93:c3:0b:df","password":""}'
{"success":true}

or machine_2 mac address ; 06:c2:93:c3:0b:df machine_2 password : passwd

user@machine_1 $ add_freebox_api lan/wol/pub '{"mac":"06:c2:93:c3:0b:df","password":"passwd"}'
{"success":true}

And it seems to work, as on machine_2, running (192.168.0.254 is my freebox local address) :

root@machine_2 # tcpdump -nnei enp0s3 -vvvttttXXX 'host 192.168.0.254'

while issuing from machine_1 :

user@machine_1 $ add_freebox_api lan/wol/pub '{"mac":"06:c2:93:c3:0b:df","password":"passwd"}'
{"success":true}

give this output on machine_2 (The Wake-On-Lan signal is recieved with the password) :

tcpdump -nnei enp0s3 -vvvttttXXX 'host 192.168.0.254' 
tcpdump: listening on enp0s3, link-type EN10MB (Ethernet), snapshot length 262144 bytes
2024-10-15 10:37:22.121794 34:27:92:XX:XX:XX > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 150: (tos 0x0, ttl 64, id 14556, offset 0, flags [DF], proto UDP (17), length 136)
    192.168.0.254.47492 > 192.168.0.255.9: [bad udp cksum 0x4bd4 -> 0x38a6!] UDP, length 108
    0x0000:  ffff ffff ffff 3427 9263 3990 0800 4500  ......4'.c9...E.
    0x0010:  0088 38dc 4000 4011 b63a c0a8 64fe c0a8  ..8.@.@..:..d...
    0x0020:  64ff b984 0009 0074 4bd4 ffff ffff ffff  d......tK.......
    0x0030:  06c2 93c3 0bdf 06c2 93c3 0bdf 06c2 93c3  ................
    0x0040:  0bdf 06c2 93c3 0bdf 06c2 93c3 0bdf 06c2  ................
    0x0050:  93c3 0bdf 06c2 93c3 0bdf 06c2 93c3 0bdf  ................
    0x0060:  06c2 93c3 0bdf 06c2 93c3 0bdf 06c2 93c3  ................
    0x0070:  0bdf 06c2 93c3 0bdf 06c2 93c3 0bdf 06c2  ................
    0x0080:  93c3 0bdf 06c2 93c3 0bdf 06c2 93c3 0bdf  ................
    0x0090:  7061 7373 7764                           passwd

So WOL seems to work fine and to be quiete easy to develop in the library

Regards nbanba

na-ji commented 1 day ago

Huh, I missed all the API CALL FUNCTIONS section on the readme. My bad, I wouldn't have asked this if I'd seen it before.

nbanb commented 1 day ago

Hi Na-ji

Thx for answering. Don't worry, no troubles you're welcome !

Everything that could be added to the library to help people with simpler commands is a good thing ! I will try to add WOL feature directly in the library, it could help people who are not familiar with json and/or bash syntax.

Also, if for your own project you develop some interesting functions using this library, please make a pull request with the code you develop, I will review and merge it (I think it would help other people), and if you develop some useful scripts using this library, don't hesitate to share them

Regarding to your original question, here is a project which you could be interesting for your use case: the core of the project is to monitor "machine up" on freebox LAN using freebox websocket API (in bash and using websocat external tool (https://github.com/vi/websocat) like this library does to access virtual machines console from the current bash session or virtual machine VNC screen) Here is the project: https://github.com/Matsuo3rd/freebox-lan-monitor For the moment I didn't find the time to add it to the library but a mix of wake-on-lan and machine detection over websocket (+ listing of LAN machines / properties) is really something which is missing today in the library, so everything regarding these points are welcome...

Kind regards nbanba

nbanb commented 19 hours ago

Dear Na-Ji

The library handle wake-on-lan now (just wake-on-lan, not machine detection). Code is merged so if you download the last version of the library you can test the new wake-on-lan function (wol_fbx).

Kind regards nbanba