Files
Domoticz/livebox_fibre.sh
2025-03-06 11:09:58 +01:00

55 lines
1.6 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Paramètres
LIVEBOX_IP="192.168.1.1"
USERNAME="admin"
PASSWORD="HYJcanGE" # Change avec ton vrai mot de passe
CURL_OPTS="-s"
# 1⃣ Authentification - obtenir le contextID
CONTEXT_ID=$(curl $CURL_OPTS -X POST "http://$LIVEBOX_IP/ws" \
-H "Content-Type: application/x-sah-ws-4-call+json" \
-H "Authorization: X-Sah-Login" \
-d "{
\"service\": \"sah.Device.Information\",
\"method\": \"createContext\",
\"parameters\": {
\"applicationName\": \"curl\",
\"username\": \"$USERNAME\",
\"password\": \"$PASSWORD\"
}
}" | jq -r '.data.contextID')
if [ -z "$CONTEXT_ID" ] || [ "$CONTEXT_ID" == "null" ]; then
echo "❌ Erreur d'authentification"
exit 1
fi
# 2⃣ Récupération de la liste des équipements connectés
DEVICE_LIST=$(curl $CURL_OPTS -X POST "http://$LIVEBOX_IP/ws" \
-H "Content-Type: application/x-sah-ws-4-call+json" \
-H "X-Context: $CONTEXT_ID" \
-d '{
"service": "NeMo.Intf.lan",
"method": "getMIBs",
"parameters": {
"mibs": "dhcp_leases"
}
}')
# 3⃣ Extraction et affichage propre
echo "📡 Appareils connectés :"
echo "$DEVICE_LIST" | jq -r '.data.dhcp_leases[] | "\(.IPAddress) - \(.HostName) - \(.MACAddress)"'
# Optionnel : déconnexion propre (fermeture de la session)
curl $CURL_OPTS -X POST "http://$LIVEBOX_IP/ws" \
-H "Content-Type: application/x-sah-ws-4-call+json" \
-H "X-Context: $CONTEXT_ID" \
-d '{
"service": "sah.Device.Information",
"method": "releaseContext",
"parameters": {}
}' > /dev/null