Displays in and out bandwidth of your network interfaces. You must also copy the included shell script.
Defaults to en0, the hardwired network interface on (most) macbooks. Invoke with en1 to change to the wireless interface.
Example
network_speed en0 en1
en0 in: 31.48 kbps
en0 out: 1.08 kbps
en1 in: 0.00 kbps
en1 out: 0.00 kbps
The script
#!/bin/zsh
PATH=/usr/sbin:/usr/bin:/bin
seconds=$1
if [ -z "$seconds" ]; then
seconds=15
else
shift
fi
divisor=`expr $seconds * 1024`
[ $divisor = 0 ] && divisor=1
[ -z "$*" ] && set "en0"
initial_bytes_in=()
initial_bytes_out=()
subsequent_bytes_in=()
subsequent_bytes_out=()
for interface in $*; do
b=`netstat -ibI $interface | awk '$3 ~ /Link/ { print $7, $10 }'`
if [ -z "$b" ]; then
initial_bytes_in+=(0)
initial_bytes_out+=(0)
else
initial_bytes_in+=(`echo $b | cut -f 1 -d " "` )
initial_bytes_out+=(`echo $b | cut -f 2 -d " "` )
fi
unset b
done
sleep $seconds
for interface in $*; do
b=`netstat -ibI $interface | awk '$3 ~ /Link/ { print $7, $10 }'`
if [ -z "$b" ]; then
subsequent_bytes_in+=(0)
subsequent_bytes_out+=(0)
else
subsequent_bytes_in+=(`echo $b | cut -f 1 -d " "` )
subsequent_bytes_out+=(`echo $b | cut -f 2 -d " "` )
fi
unset b
done
for i in {1..$#*}; do
printf "$*[$i] in: %04.2f kbpsn" `echo "scale=2; ($subsequent_bytes_in[$i] - $initial_bytes_in[$i])/$divisor" | bc 2>/dev/null`
printf "$*[$i] out: %04.2f kbpsn" `echo "scale=2; ($subsequent_bytes_out[$i] - $initial_bytes_out[$i])/$divisor" | bc 2>/dev/null`
done