[download]

local/bin/network

   1 #!/bin/bash
   2 #         ░███████
   3 #       ░███████       D O T F I L E S
   4 #       ░███████       N E T W O R K
   5 #    ░█████████████
   6 #       ░███████
   7 #       ░███████       LGPL <http://www.gnu.org/licenses/>
   8 #       ░██  ░██
   9 #       ░██  ░██   (C) 2020 Alexey Gagin <http://www.lexa.by/dotfiles/>
  10 
  11 f=~/.cache/network
  12 
  13 echo "Network   : $(ip r g 1 | awk '{ print $3 }')"
  14 echo "Interface : $(ip r g 1 | awk '{ print $5 }')"
  15 echo "IP Local  : $(ip r g 1 | awk '{ print $7 }')"
  16 
  17 echo "IP Public : $(curl -sm 1 ipinfo.io/ip)"
  18 echo "IP Socks5 : $(curl -sm 1 ipinfo.io/ip --socks5 localhost:9050)"
  19 
  20 [[ $(curl -sm 1 192.168.8.1) ]] && {
  21     url=http://192.168.8.1/api
  22     sid=$(curl -s   $url/webserver/SesTokInfo | grep -o 'SessionID=[^<]*')
  23     xml=$(curl -sH "Cookie: $sid" $url/monitoring/status | sed 's/[<>]/ /g')
  24 
  25     con=$(echo "$xml" | awk '/NetworkType / { print $2 }')
  26     case $con in
  27       0|4) con=?;;
  28         3) con=2g;;
  29         9) con=3g;;
  30        19) con=4g;;
  31     esac
  32     echo "Con Type  : $con"
  33 
  34     max=$(echo "$xml" | awk '/maxsignal /  { print $2 }')
  35     sig=$(echo "$xml" | awk '/SignalIcon / { print $2 }')
  36     echo "Con Signal: $(( sig / max * 100 ))%"
  37 }
  38 
  39 [[ $1 == -u || ! -f $f-speed ]] &&
  40 speedtest-cli --simple | awk 'NR > 1 { print $2, $3 }' > $f-speed
  41 
  42 echo "Speed DL  : $(sed '1q;d' $f-speed)"
  43 echo "Speed UP  : $(sed '2q;d' $f-speed)"