[download]

local/bin/e3372

   1 #!/bin/bash
   2 
   3 declare -A array
   4 url=http://192.168.8.1/api
   5 sid=$(curl -sm 1 $url/webserver/SesTokInfo | grep -o 'SessionID=[^<]*') || exit 1
   6 
   7 while IFS=\> read -d \< tag value; do
   8     [[ $tag == [a-zA-Z]* ]] && array[$tag]=$value
   9 done < <(
  10   curl -sH "Cookie: $sid" $url/monitoring/status
  11   curl -sH "Cookie: $sid" $url/monitoring/traffic-statistics
  12   curl -sH "Cookie: $sid" $url/net/current-plmn
  13 )
  14 
  15 max=${array[maxsignal]}
  16 sig=${array[SignalIcon]}
  17 sig=$(( sig / max * 100 ))
  18 
  19 t=${array[CurrentConnectTime]}
  20 h=$(( t / 60 / 60 ))
  21 m=$(( t / 60 % 60 ))
  22 s=$(( t % 60 ))
  23 
  24 case ${array[CurrentNetworkType]} in
  25      0) type=0g;;
  26      1) type=2g;; # GSM
  27      2) type=2g;; # GPRS
  28      3) type=2g;; # EDGE
  29      4) type=3g;; # W-CDMA
  30      5) type=3g;; # HSDPA
  31      6) type=3g;; # HSUPA
  32      7) type=3g;; # HSPA
  33      8) type=3g;; # TD-SCDMA
  34      9) type=3g;; # HSPA+
  35     10) type=3g;; # EV-DO Rel. 0
  36     11) type=3g;; # EV-DO Rev. A
  37     12) type=3g;; # EV-DO Rev. B
  38     13) type=2g;; # 1xRTT
  39   # 14) type=?g;; # UMB
  40     15) type=2g;; # 1xEV-DV
  41     17) type=3g;; # HSPA+ 64QAM
  42     18) type=3g;; # HSPA+ MIMO
  43     19) type=4g;; # LTE
  44 esac
  45 
  46 printf '%s\t%s\t%s\t%s\t%s\t%s\n' \
  47 "${array[ShortName]}" $type $sig% \
  48 $(echo ${array[CurrentDownload]} | numfmt --to iec --suffix B) \
  49 $(echo ${array[CurrentUpload]}   | numfmt --to iec --suffix B) \
  50 $(printf '%02d:%02d:%02d' $h $m $s) | tee ~/.cache/e3372