[download]

local/bin/network

   1 #!/bin/bash
   2 
   3 printf '%s\t%s\n' \
   4 'Network ' $(ip r g 1 | awk '{ print $3 }') \
   5 Interface  $(ip r g 1 | awk '{ print $5 }')
   6 
   7 awk '/^\w+:/ {
   8     gsub(":", "")
   9     printf "%s\t%s%%\n", $1, int($3 * 100 / 70)
  10 }' /proc/net/wireless
  11 
  12 if [[ $(curl -sm 1 192.168.8.1) ]]; then
  13     url=http://192.168.8.1/api
  14     sid=$(curl -s   $url/webserver/SesTokInfo | grep -o 'SessionID=[^<]*')
  15     xml=$(curl -sH "Cookie: $sid" $url/monitoring/status | sed 's/[<>]/ /g')
  16 
  17     con=$(echo "$xml" | awk '/NetworkType / { print $2 }')
  18     case $con in
  19       0|4) con=?;;
  20         3) con=2g;;
  21         9) con=3g;;
  22        19) con=4g;;
  23     esac
  24 
  25     printf 'LTE %s\t%s%%\n' \
  26     Type $con Signal $(echo "$xml" | awk '
  27         /SignalIcon / { s = $2 }
  28         /maxsignal /  { m = $2 }
  29         END { print s / m * 100 }
  30     ')
  31 fi
  32 
  33 printf 'IP %s\t%s\n' \
  34 Local  "$(ip r g 1 | awk '{ print $7 }')" \
  35 Public "$(curl -sm 1 ifconfig.me)" \
  36 Socks5 "$(curl -sm 1 ifconfig.me --socks5 localhost:9050)"