From 4489f22ac08ab96f92a5630d34c43d499408fb31 Mon Sep 17 00:00:00 2001 From: Philippe Caseiro Date: Tue, 18 Sep 2018 14:36:45 +0200 Subject: [PATCH] Adding experimentation shell scripts ! --- scripts/experiment/luciRpc.sh | 90 +++++++++++++++++++++++++++++++++++ scripts/experiment/uciCli.sh | 26 ++++++++++ 2 files changed, 116 insertions(+) create mode 100644 scripts/experiment/luciRpc.sh create mode 100644 scripts/experiment/uciCli.sh diff --git a/scripts/experiment/luciRpc.sh b/scripts/experiment/luciRpc.sh new file mode 100644 index 0000000..00ea02f --- /dev/null +++ b/scripts/experiment/luciRpc.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +function rpcLogin() { + local IP=$1 + local PORT=$2 + local USER="$3" + local PASS="$4" + local RES="" + + local cmd="curl" + local url="http://${IP}:${PORT}/cgi-bin/luci/rpc/auth" + local opt="--silent --data" + local data="{ \"id\": 1, \"method\": \"login\", \"params\": [ \"$USER\", \"$PASS\" ] }" + + res=$(${cmd} ${url} ${opt} "${data}") + echo ${res} | jq -Ma ".result" +} + +function iwList() +{ + local IP=$1 + local PORT=$2 + local IFACE=$3 + local TOKEN="$4" + + local cmd="curl" + local url="http://${IP}:${PORT}/cgi-bin/luci/rpc/sys" + local opt="--silent --cookie sysauth=${TOKEN} --data" + local data="{ \"method\": \"wifi.getiwinfo\", \"params\": [ \"${IFACE}\" ] }" + + res=$(${cmd} ${url} ${opt} "${data}") + echo ${res} |jq +} + +function netDeviceInfo() +{ + local IP=$1 + local PORT=$2 + local TOKEN="$3" + + local cmd="curl" + local url="http://${IP}:${PORT}/cgi-bin/luci/rpc/sys" + local opt="--silent --cookie sysauth=${TOKEN} --data" + local data="{ \"method\": \"net.deviceinfo\", \"params\": [ \"wlan0\" ]}" + + res=$(${cmd} ${url} ${opt} "${data}") + echo ${res} |jq + +} + +function netDevices() +{ + local IP=$1 + local PORT=$2 + local TOKEN="$3" + + local cmd="curl" + local url="http://${IP}:${PORT}/cgi-bin/luci/rpc/sys" + local opt="--silent --cookie sysauth=${TOKEN} --data" + local data="{ \"method\": \"net.devices\", \"params\": [] }" + + res=$(${cmd} ${url} ${opt} "${data}") + echo ${res} |jq +} + +function arpTable() +{ + local IP=$1 + local PORT=$2 + local TOKEN="$3" + + local cmd="curl" + local url="http://${IP}:${PORT}/cgi-bin/luci/rpc/sys" + local opt="--silent --cookie sysauth=${TOKEN} --data" + local data="{ \"method\": \"net.arptable\", \"params\": [] }" + + res=$(${cmd} ${url} ${opt} "${data}") + echo ${res} |jq +} + +#FIXME USER PASS +authToken=$(rpcLogin 192.168.1.1 8080 root 'XXXXXX EDITE MOI') + +#netDevices 192.168.1.1 8080 ${authToken} +#netDeviceInfo 192.168.1.1 8080 ${authToken} +#iwList 192.168.1.1 8080 wlan0 ${authToken} +#iwList 192.168.1.1 8080 wlan1 ${authToken} + +adoles: + diff --git a/scripts/experiment/uciCli.sh b/scripts/experiment/uciCli.sh new file mode 100644 index 0000000..788f0fd --- /dev/null +++ b/scripts/experiment/uciCli.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +function scanWifi() +{ + local ifcace=$1 + iwconfig ${iface} scan +} + +function connectBoard() +{ + uci delete wireless.@wifi-iface[1] + uci add wireless wifi-iface + uci set wireless.@wifi-iface[1].network="EmlidReach" + uci set wireless.@wifi-iface[1].ssid="Base1:2a:03" + uci set wireless.@wifi-iface[1].encryption="psk2" + uci set wireless.@wifi-iface[1].device="radio1" + uci set wireless.@wifi-iface[1].mode="sta" + uci set wireless.@wifi-iface[1].bssid="FC:DB:B3:7E:2A:03" + uci set wireless.@wifi-iface[1].key="basepyxis" + uci commit + reload_config + sleep 15 + udhcpc -i wlan1 +} + +cells=$(scanWifi wlan1)