20-network
This commit is contained in:
parent
87abcdd954
commit
ad1f884281
29
20-network
Normal file
29
20-network
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
interface=$(ip -o -4 route show to default | awk '{print $5}')
|
||||||
|
|
||||||
|
nic_in=$(grep $interface /proc/net/dev | awk '{print $2}')
|
||||||
|
nic_out=$(grep $interface /proc/net/dev | awk '{print $10}')
|
||||||
|
|
||||||
|
function human_readable {
|
||||||
|
VALUE=$1
|
||||||
|
if ! [[ "$VALUE" =~ ^[0-9]+$ ]]; then
|
||||||
|
echo "0B"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
BIGGIFIERS=( B Kb Mb Gb )
|
||||||
|
CURRENT_BIGGIFIER=0
|
||||||
|
while [ $VALUE -gt 10000 ] ;do
|
||||||
|
VALUE=$(($VALUE/1000))
|
||||||
|
CURRENT_BIGGIFIER=$((CURRENT_BIGGIFIER+1))
|
||||||
|
done
|
||||||
|
echo "$VALUE${BIGGIFIERS[$CURRENT_BIGGIFIER]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
system_ip=$(hostname -I)
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "Network information:"
|
||||||
|
printf "System IP:\t%s\n" $system_ip
|
||||||
|
printf "Traffic in:\t%s\tTraffic out:\t%s\n" `human_readable $nic_in` `human_readable $nic_out`
|
||||||
|
echo
|
||||||
Reference in New Issue
Block a user