net speed i3

bar{
 status_command exec ~/.config/i3/net-speed.sh
}

ls ls  /sys/class/net
to find ifaces= list of interfaces to show speed like eth0,enp8s0,etc


 touch ~/.config/i3/net-speed.sh
nano ~/.config/i3/net-speed.sh
-------------------------------------------------------------------------------------------------------------------------------------
ifaces="wlp0s20u2"
last_time=0
last_rx=0
last_tx=0
rate=""

readable() {
  local bytes=$1
  local kib=$(( bytes >> 10 ))
  if [ $kib -lt 0 ]; then
    echo "? K"
  elif [ $kib -gt 1024 ]; then
    local mib_int=$(( kib >> 10 ))
    local mib_dec=$(( kib % 1024 * 976 /
10000 ))
    if [ "$mib_dec" -lt 10 ]; then
      mib_dec="0${mib_dec}"
    fi
    echo "${mib_int}.${mib_dec} M"
  else
    echo "${kib} K"
  fi
}

update_rate() {
  local time=$(date +%s)
  local rx=0 tx=0 tmp_rx tmp_tx

  for iface in $ifaces; do
    read tmp_rx <  "/sys/class/net/${iface}/statistics/rx_bytes"
    read tmp_tx < "/sys/class/net/${iface}/statistics/tx_bytes"
    rx=$(( rx + tmp_rx ))
    tx=$(( tx + tmp_tx ))
  done

  local interval=$(( $time - $last_time
))
  if [ $interval -gt 0 ]; then
    rate="$(readable $(( (rx - last_rx) /
interval )))↓ $(readable $(( (tx -
last_tx) / interval )))↑"
  else
    rate=""
  fi

  last_time=$time
  last_rx=$rx
  last_tx=$tx
}

i3status | (read line && echo "$line" &&
read line && echo "$line" && read line &&
echo "$line" && update_rate && while :
do
  read line
  update_rate
  echo ",[{\"full_text\":\"${rate}\"
},${line#,\[}" || exit 1
done)
----------------------------------------------------------------------------------------------------------------------------------
test the script and add the line on bar{} in i3config file.

source:http://code.stapelberg.de/git/i3status/tree/contrib/net-speed.sh

vpn not use

United States, United Kingdom, Australia, New Zealand, Canada, Denmark, France, Netherlands, Norway, Belgium, Germany, Italy, Spain, Israel...