Get Ethernet and WiFi bandwidth in Android

Ethernet:- Make ethernet_bw.sh file. Copy below code snippet in file. [code lang=”bash”] #!/bin/sh INTERVAL=”1″ # update interval in seconds while true do R1=`cat /sys/class/net/eth0/statistics/rx_bytes` T1=`cat /sys/class/net/eth0/statistics/tx_bytes` sleep $INTERVAL R2=`cat /sys/class/net/eth0/statistics/rx_bytes` T2=`cat /sys/class/net/eth0/statistics/tx_bytes` TBPS=`expr $T2 – $T1` RBPS=`expr $R2 – $R1` TKBPS=`expr $TBPS / 1024` RKBPS=`expr $RBPS / 1024` echo “TX eth0: $TKBPS kB/s RX eth0:…


Ethernet:-

  • Make ethernet_bw.sh file.
  • Copy below code snippet in file.

[code lang=”bash”]
#!/bin/sh
INTERVAL=”1″ # update interval in seconds
while true
do
R1=`cat /sys/class/net/eth0/statistics/rx_bytes`
T1=`cat /sys/class/net/eth0/statistics/tx_bytes`
sleep $INTERVAL
R2=`cat /sys/class/net/eth0/statistics/rx_bytes`
T2=`cat /sys/class/net/eth0/statistics/tx_bytes`
TBPS=`expr $T2 – $T1`
RBPS=`expr $R2 – $R1`
TKBPS=`expr $TBPS / 1024`
RKBPS=`expr $RBPS / 1024`
echo “TX eth0: $TKBPS kB/s RX eth0: $RKBPS kB/s”
done
[/code]

  • Push ethernet_bw.sh file to Android device through ADB and start script.

WiFi :-

  • Make wifi_bw.sh file.
  • Copy below code snippet in file.

[code lang=”bash”]
#!/bin/sh
INTERVAL=”1″ # update interval in seconds
while true
do
R1=`cat /sys/class/net/wlan0/statistics/rx_bytes`
T1=`cat /sys/class/net/wlan0/statistics/tx_bytes`
sleep $INTERVAL
R2=`cat /sys/class/net/wlan0/statistics/rx_bytes`
T2=`cat /sys/class/net/wlan0/statistics/tx_bytes`
TBPS=`expr $T2 – $T1`
RBPS=`expr $R2 – $R1`
TKBPS=`expr $TBPS / 1024`
RKBPS=`expr $RBPS / 1024`
echo “TX eth0: $TKBPS kB/s RX eth0: $RKBPS kB/s”
done
[/code]

  • Push wifi_bw.sh file to Android device through ADB and start script.

Leave a Reply

Discover more from Prabhu System Technology

Subscribe now to keep reading and get access to the full archive.

Continue reading