[download]

local/bin/network

   1 #!/bin/bash
   2 
   3 f=~/.cache/network
   4 
   5 echo "Network   : $(ip r g 1 | awk '{ print $3 }')"
   6 echo "Interface : $(ip r g 1 | awk '{ print $5 }')"
   7 echo "IP Local  : $(ip r g 1 | awk '{ print $7 }')"
   8 
   9 echo "IP Public : $(curl -sm 1 ifconfig.me)"
  10 echo "IP Socks5 : $(curl -sm 1 ifconfig.me --socks5 localhost:9050)"
  11 
  12 [[ $(curl -sm 1 192.168.8.1) ]] && {
  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     echo "Con Type  : $con"
  25 
  26     echo "Con Signal: $(echo "$xml" | awk '
  27         /SignalIcon / { s=$2 }
  28         /maxsignal /  { m=$2 }
  29         END { print s / m * 100 }
  30     ')%"
  31 }
  32 
  33 a=$(awk '{ a+=$2; b+=$10 } END { print a, b }' /proc/net/dev)
  34 wget -qO /dev/null http://mirror.yandex.ru/archlinux/iso/2020.08.01/archlinux-2020.08.01-x86_64.iso &
  35 pid=$! && sleep 1 && kill $pid
  36 b=$(awk '{ a+=$2; b+=$10 } END { print a, b }' /proc/net/dev)
  37 
  38 read dl up < <(echo "$b $a" |
  39 awk '{ print ($1 - $3), ($2 - $4) }' |
  40 numfmt --field=1,2 --to=iec --suffix=B/s)
  41 
  42 echo "Speed DL  : $dl"
  43 echo "Speed UP  : $up"