-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript-shell-livebox-4.sh
More file actions
71 lines (50 loc) · 3.81 KB
/
script-shell-livebox-4.sh
File metadata and controls
71 lines (50 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Script de récupération des informations pour LIVEBOX4
# Pour utiliser ce script vous devez avoir accés aux commandes curl et jq (json query)
# Il vous suffit de compléter les 2 variables ci-dessous avec vos paramètres
# J.LASSON - 2019
myLivebox=192.168.1.1
myPassword="votremotdepasse"
# Récupère le chemin où est lancé le script
myBashDir=`readlink -f $0 | xargs dirname`
myOutput=$myBashDir/myOutput.txt
myCookies=$myBashDir/myCookies.txt
# Connexion et recuperation du cookies
postData="{\"service\":\"sah.Device.Information\",\"method\":\"createContext\",\"parameters\":{\"applicationName\":\"so_sdkut\",\"username\":\"admin\",\"password\":\"${myPassword}\"}}"
curl -s -o "$myOutput" -X POST -c "$myCookies" -H 'Content-Type: application/x-sah-ws-1-call+json' -H 'Authorization: X-Sah-Login' -d $postData "http://${myLivebox}/ws" > /dev/null
# Lecture du cookies pour utilisation ulterieure
myContextID=`jq -r .data.contextID $myOutput`
# Préparation de la récuperation des json
getMIBs=`curl -s -b "$myCookies" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H "X-Context: $myContextID" -d "{\"service\":\"NeMo.Intf.data\",\"method\":\"getMIBs\",\"parameters\":{}}" http://${myLivebox}/ws`
getDSLStats=`curl -s -b "$myCookies" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H "X-Context: $myContextID" -d "{\"service\":\"NeMo.Intf.dsl0\",\"method\":\"getDSLStats\",\"parameters\":{}}" http://${myLivebox}/ws`
getWANStatus=`curl -s -b "$myCookies" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H "X-Context: $myContextID" -d "{\"service\":\"NMC\",\"method\":\"getWANStatus\",\"parameters\":{}}" http://${myLivebox}/ws`
getDeviceInfo=`curl -s -b "$myCookies" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H "X-Context: $myContextID" -d "{\"service\":\"DeviceInfo\",\"method\":\"get\",\"parameters\":{}}" http://${myLivebox}/ws`
getDevices=`curl -s -b "$myCookies" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H "X-Context: $myContextID" -d "{\"service\":\"Devices\",\"method\":\"get\",\"parameters\":{}}" http://${myLivebox}/ws`
# Affichage du resultat
# Là je mets tout dans un fichier texte mais libre à vous de choisir
# jq permet en plus de filtrer sur des valeurs précises
# Exemples :
# echo $getDSLStats | jq -r .status.TransmitBlocks
# echo $getDSLStats | jq -r .status.ReceiveBlocks
echo "RAPPORT DU :" > $myBashDir/Result.txt
date +"%Y-%m-%d %Hh%Mm%Ss" >> $myBashDir/Result.txt
echo "--------------------------------------------------------" >> $myBashDir/Result.txt
echo "Info sur la LIVEBOX :" >> $myBashDir/Result.txt
echo "--------------------------------------------------------" >> $myBashDir/Result.txt
echo $getDeviceInfo | jq . >> $myBashDir/Result.txt
echo "Info sur les paramètres (MIBs) :" >> $myBashDir/Result.txt
echo "--------------------------------------------------------" >> $myBashDir/Result.txt
echo $getMIBs | jq . >> $myBashDir/Result.txt
echo "Info sur les indicateurs DSL :" >> $myBashDir/Result.txt
echo "--------------------------------------------------------" >> $myBashDir/Result.txt
echo $getDSLStats | jq . >> $myBashDir/Result.txt
echo "Info sur la configuration du WAN :" >> $myBashDir/Result.txt
echo "--------------------------------------------------------" >> $myBashDir/Result.txt
echo $getWANStatus | jq . >> $myBashDir/Result.txt
echo "Info sur les Devices connectés à la BOX :" >> $myBashDir/Result.txt
echo "--------------------------------------------------------" >> $myBashDir/Result.txt
echo $getDevices | jq . >> $myBashDir/Result.txt
# Deconnexion et suppression des fichiers temporaires
curl -s -b "$myCookies" -X POST http://$myLivebox/logout > /dev/null
rm "$myCookies" "$myOutput"
# pour être complet il existe des methodes set pour scripter des changements de valeurs
# Exemple : Activation / Désactivation du Wifi