I looked at the/proc/net/dev under Linux to record the number of packets and bytes sent and received by each network card. So initiation thought, wrote one. Operation Effect:
Copy Code code as follows:
[root@74-82-173-217 ~]#./net.sh
Current Ip:inet addr:74.82.173.217 bcast:74.82.173.223 mask:255.255.255.224
Summry info:rx bytes:203692709 (194.2 MiB) TX bytes:93525930 (89.1 MiB)
Eth0 Receive bytes:573 Packets:3
Eth0 Send bytes:3086 Packets:3
Eth0 Receive bytes:378 packets:7
Eth0 Send bytes:11236 packets:7
Eth0 Receive bytes:324 Packets:6
Eth0 Send bytes:444 Packets:2
Eth0 Receive bytes:54 packets:1
Eth0 Send bytes:0 packets:0
The content of the specific script is as follows, almost no need to modify, you can get any machine to use.
Copy Code code as follows:
[root@74-82-173-217 ~]# Cat net.sh
#! /bin/bash
#Author: Vogts Wangtao 2008-12-18
#Get Summry Info
echo "Current Ip:" '/sbin/ifconfig eth0 | grep inet '
echo "Summry info:" '/sbin/ifconfig eth0 | grep bytes '
#sleep 1 second, monitor eth0
While True
Todo
receive1= ' Cat/proc/net/dev|grep eth0 | awk ' {print$1} ' |sed-s ' s/eth0://g '
receive_pack1= ' Cat/proc/net/dev|grep eth0 | awk ' {print$2} '
send1= ' Cat/proc/net/dev|grep eth0 | awk ' {print$9} '
send_pack1= ' Cat/proc/net/dev|grep eth0 | awk ' {print$10} '
Sleep 1
Receive2= ' Cat/proc/net/dev|grep eth0 | awk ' {print$1} ' |sed-s ' s/eth0://g '
Receive_pack2= ' Cat/proc/net/dev|grep eth0 | awk ' {print$2} '
receive_cnt= ' Expr $receive 2-$receive 1 '
receive_pack_cnt= ' expr $receive _pack2-$receive _pack1 '
Send2= ' Cat/proc/net/dev|grep eth0 | awk ' {print$9} '
Send_pack2= ' Cat/proc/net/dev|grep eth0 | awk ' {print$10} '
send_cnt= ' Expr $send 2-$send 1 '
send_pack_cnt= ' expr $send _pack2-$send _pack1 '
Echo ' eth0 Receive Bytes: ' $receive _cnt ' Packets: ' $receive _pack_cnt
Echo ' eth0 Send Bytes: ' $send _cnt ' Packets: ' $send _pack_cnt
Done