Get Linux network traffic script
Syntax: [-- help] [-I] [-D]
#! /Bin/bash
Version = "1.0.0.1"
Eth = ""
SEC = 0
Help ()
{
Printf "version: $ version \ n \
Usage: $0 [-I interface] [-D time] \ n \
\ T-I | -- interface: The needs of the inquiries interface network card (such as eth0, eth1...) \ n \
\ T-d | -- Time: Delay Time (seconds) \ n ";
}
Echo "$ *"
For dummy
Do
Case $1 in
-- Help) help; Exit 1 ;;
-I | -- Interface) shift; Eth = $1 ;;
-D | -- Time) shift; sec = $1 ;;
Esac
Shift
Done
# echo-n "Please enter the Needs of the inquiries interface network card (such as eth0, eth1 ...): "
# Read ETH
echo" your input data is: "$ ETH
# echo-n" input delay time (seconds ): "
# Read sec
echo" you are calculated within "$ sec" seconds of the average flow, please wait... "
infirst = $ (awk '/' $ ETH '/{print $1}'/proc/NET/dev | SED's/'$ ETH ': // ')
outfirst = $ (awk'/'$ ETH'/{print $10} '/proc/NET/Dev)
sumfirst = $ ($ infirst + $ outfirst ))
sleep $ sec "S"
inend = $ (awk '/' $ ETH '/{print $1}'/proc/NET/dev | SED's /'$ ETH ': // ')
outend = $ (awk'/'$ ETH'/{print $10} '/proc/NET/Dev)
sumend = $ ($ inend + $ outend)
sum = $ ($ sumend-$ sumfirst)
echo $ sec "(s) total flow is: "$ sum" bytes "
aver =$ ($ sum/$ Sec)
echo" The average flow is: "$ aver" Bytes/sec "