Skip to content

Instantly share code, notes, and snippets.

@sport4minus
Created February 21, 2023 19:37
Show Gist options
  • Save sport4minus/32f2b31acaa34f1a7687de57b1cc73d7 to your computer and use it in GitHub Desktop.
Save sport4minus/32f2b31acaa34f1a7687de57b1cc73d7 to your computer and use it in GitHub Desktop.
python script to control a Brennenstuhl Premium-Web-Line V3
# Brennenstuhl Premium-Web-Line V3 is a socket strip with an embedded web server.
# It can be switched via a web interface or using http get requests. The latter is a bit under-documented,
# so here's what i found out:
# The built-in server accepts only authenticated http get requests (using digest auth).
# each command has its own url, like so: http://{IP-OF-THE-SOCKETSTRIP}/cgi/{commandname}?params
# full list can be found in a PDF called "Premium-Web-Line V3 CGI specification.pdf" which is included in the download package of the official software:
# download link -> https://www.brennenstuhl.com/index.php?module=explorer&index[explorer][action]=download&index[explorer][file]=firmware/premium-web-line-v3-software-3_3_6.zip
# here's an example on how to toggle one of the two relais (nr. 0)
# modified a general digest auth example from stackoverflow: https://stackoverflow.com/questions/23254013/http-digest-basic-auth-with-python-requests-module
import logging
import requests
from requests.auth import HTTPDigestAuth
try:
import httplib
except ImportError:
import http.client as httplib
httplib.HTTPConnection.debuglevel = 1
# you need to initialize logging,
# otherwise you will not see anything from requests
logging.basicConfig(level=logging.DEBUG)
# make request
url = 'http://10.0.1.118/cgi/toggleRelay?Rel=0' #Rel=1 would toggle the other relay
# user / password is factory set to admin/admin - you better change this quick.
r = requests.get(url, auth=HTTPDigestAuth('admin', 'admin'),
timeout=10)
print(r.status_code)
print(r.headers)
@lukas-hofstaetter
Copy link

Great! Thankyou! I always tried the same via curl but that does not work. Foreverboy searching a one-liner:

python3 -c "import requests; r = requests.get('http://192.168.0.12/cgi/toggleRelay?Rel=0', auth=requests.auth.HTTPDigestAuth('admin', 'admin'), timeout=10); print(r.status_code)"

@sport4minus
Copy link
Author

Thank you, very useful 👍
i also tried curl but never got the parameters right..
then python.
I would really like to how it's done though...

@lukas-hofstaetter
Copy link

Yeah, curl can also do a getand a digest authentication.. But I always get a permission denied" error. Maybe I should do a Wireshark debug session to understand the difference between the python and the curl command. Would be a nice learning.

@sport4minus
Copy link
Author

same here – if you find the time to do that, i'd be curious to hear why it fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment