Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - MauMo

#1
General Discussion / Re: API for WOL with Curl
May 22, 2024, 04:10:20 PM
Hi HansJ
i was stuck at the same error message.

My solution was an python script:


import http.client
import json
import ssl

conn = http.client.HTTPSConnection('$OPNsenseIP:$Port', context=ssl._create_unverified_context())
headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Basic %Base64 Coded API and Secret Key%',
}
json_data = {
    'wake': {
        'interface': 'opt1',
        'mac': '00:00:00:00:00:00',
    },
}
conn.request(
    'POST',
    '/api/wol/wol/set',
    json.dumps(json_data),
    # '{"wake":{"interface":"opt1","mac":"00:00:00:00:00:00"}}',
    headers
)
response = conn.getresponse()


Save it as wol.py for example. Make sure you insert the right interface and MAC.

The python script ist auto generated from here: https://curlconverter.com/python-httpclient/
It will transform the OPNsense API key and secret automaticaly to Base64 for Basic Auth.

My original curl prompt was:


curl -X POST -H 'Content-Type:application/json' -d '{"wake":{"interface":"opt1","mac":"00:00:00:00:00:00"}}' -k -u "$API-Key:$API-Secret" https://$OPNsenseIP:$Port/api/wol/wol/set



In Windows you have to install python from https://www.python.org/downloads/windows/

When installing add python to system path global vars in Windows.

You can now start your wol.py via cmd or batch script


@echo off
python C:\pathtopythonscriptfile\wol.py
pause