亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2613 | 回復: 7
打印 上一主題 下一主題

如何把文本文件內(nèi)容,結(jié)合ipfw命令寫入帶寬限制表中去? [復制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2009-02-17 17:35 |只看該作者 |倒序瀏覽
現(xiàn)在有文本bandwidth.conf內(nèi)容:
11.0.0.2 512 256
11.0.0.3 256 128
。。。。。。
11.0.0.2為限制的ip,512為下載值,256為上傳值。

現(xiàn)在想通過shell腳本,結(jié)合ipfw帶寬限制命令,批量把文本內(nèi)的:ip、下載值和上傳值寫入帶寬限制表

中去。通過這幾個命令:
ipfw pipe 1 config bw 下載值Kbit/s
ipfw pipe 2 config bw 上傳值Kbit/s
ipfw add 9000 pipe 1 ip from any to ip地址 in
ipfw add 9001 pipe 2 ip from ip地址 to any out
ipfw add 9002 permit ip from any to ip地址
ipfw add 9003 permit ip from ip地址 to any

請教這個腳本如何寫啊

論壇徽章:
0
2 [報告]
發(fā)表于 2009-02-17 17:52 |只看該作者
awk '{
printf "ipfw pipe 1 config bw %dKbit/s\n",$2;
printf "ipfw pipe 2 config bw %dKbit/s\n",$3;
printf "ipfw add 9000 pipe 1 %s from any to ip地址 in\n",$1
}' bandwidth.conf

論壇徽章:
0
3 [報告]
發(fā)表于 2009-02-17 18:02 |只看該作者
不太明白啊

論壇徽章:
0
4 [報告]
發(fā)表于 2009-02-17 19:58 |只看該作者
while read line
do
IP=`echo "$line"|awk '{print $1}'`
DOWNLOAD=`echo "$line"|awk '{print $2}'`
UPLOAD=`echo "$line"|awk '{print $3}'`

ipfw pipe 1 config bw ${DOWNLOAD} Kbit/s
ipfw pipe 2 config bw ${UPLOAD} Kbit/s
ipfw add 9000 pipe 1 ip from any to $IP in
ipfw add 9001 pipe 2 ip from $IP to any out
ipfw add 9002 permit ip from any to $IP
ipfw add 9003 permit ip from $IP to any
done < bandwidth.conf

論壇徽章:
0
5 [報告]
發(fā)表于 2009-02-18 10:10 |只看該作者
while read line
do
IP=`echo "$line"|awk '{print $1}'`
DOWNLOAD=`echo "$line"|awk '{print $2}'`
UPLOAD=`echo "$line"|awk '{print $3}'`

ipfw pipe 1 config bw ${DOWNLOAD} Kbit/s
ipfw pipe 2 config bw ${UPLOAD} Kbit/s
ipfw add 9000 pipe 1 ip from any to $IP in
ipfw add 9001 pipe 2 ip from $IP to any out
ipfw add 9002 permit ip from any to $IP
ipfw add 9003 permit ip from $IP to any
done < bandwidth.conf
"test.sh" 17 lines, 563 characters
router# ./test.sh
while: Expression Syntax.
router# ipfw show
65535 7497 3625045 allow ip from any to any
不行,不能加入限制表

論壇徽章:
0
6 [報告]
發(fā)表于 2009-02-18 10:57 |只看該作者

回復 #5 lhm_3000 的帖子

不明白你哪的問題
我這邊測試過是可以的。
你用sh -x 調(diào)試看一下

論壇徽章:
11
金牛座
日期:2015-03-19 16:56:22數(shù)據(jù)庫技術版塊每日發(fā)帖之星
日期:2016-08-02 06:20:00數(shù)據(jù)庫技術版塊每日發(fā)帖之星
日期:2016-04-24 06:20:00數(shù)據(jù)庫技術版塊每日發(fā)帖之星
日期:2016-04-13 06:20:00IT運維版塊每日發(fā)帖之星
日期:2016-04-13 06:20:00數(shù)據(jù)庫技術版塊每日發(fā)帖之星
日期:2016-02-03 06:20:00數(shù)據(jù)庫技術版塊每日發(fā)帖之星
日期:2015-08-06 06:20:00季節(jié)之章:春
日期:2015-03-27 15:54:57羊年新春福章
日期:2015-03-27 15:54:37戌狗
日期:2015-03-19 16:56:41數(shù)據(jù)庫技術版塊每日發(fā)帖之星
日期:2016-08-18 06:20:00
7 [報告]
發(fā)表于 2009-02-18 10:59 |只看該作者
這個是體力活.....沒什么技巧可言...

論壇徽章:
0
8 [報告]
發(fā)表于 2009-02-18 12:03 |只看該作者
已經(jīng)基本搞好現(xiàn)在文本文件:
11.0.0.2 500 80 1
11.0.0.3 4096 2048 2
11.0.0.4 512 80 3
......
11.0.0.2為地址,500為下行,80為上行值,1為序號
腳本修改了以下:
router# cat test.sh
fwcmd=/sbin/ipfw
$fwcmd flush
$fwcmd pipe flush

while read line
do
usernum=`echo "$line"|awk '{print $4}'`
pipein=`echo $usernum*2 | bc`
pipeout=`expr $pipein + 1`
fwrulein=`expr $pipein + 1000`
fwruleout=`expr $fwrulein + 1`
fwholein=`expr $pipein + 33000`
fwholeout=`expr $fwholein + 1`
#LIST=`echo "$line"|awk '{print $4}'`
#PIPE=`expr $LIST + 1`

IP=`echo "$line"|awk '{print $1}'`
DOWNLOAD=`echo "$line"|awk '{print $2}'`
UPLOAD=`echo "$line"|awk '{print $3}'`

$fwcmd pipe $pipein config bw ${DOWNLOAD}Kbit/s
$fwcmd pipe $pipeout config bw ${UPLOAD}Kbit/s
$fwcmd add $fwrulein pipe $pipein ip from any to $IP in
$fwcmd add $fwruleout pipe $pipeout ip from $IP to any out
$fwcmd add $fwholein permit ip from any to $IP
$fwcmd add $fwholeout permit ip from $IP to any
done < /usr/local/etc/mpd/bandwidth.conf

現(xiàn)在規(guī)則可以加入了,請看:
router# ipfw pipe show
00002: 500.000 Kbit/s    0 ms   50 sl. 1 queues (1 buckets) droptail
    mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000
BKT Prot ___Source IP/port____ ____Dest. IP/port____ Tot_pkt/bytes Pkt/Byte Drp
  0 tcp      58.60.14.45/80           11.0.0.2/2640    76     8660  0    0   0
00003:  80.000 Kbit/s    0 ms   50 sl. 0 queues (1 buckets) droptail
00004:   4.096 Mbit/s    0 ms   50 sl. 0 queues (1 buckets) droptail
00005:   2.048 Mbit/s    0 ms   50 sl. 0 queues (1 buckets) droptail
00006: 512.000 Kbit/s    0 ms   50 sl. 0 queues (1 buckets) droptail
00007:  80.000 Kbit/s    0 ms   50 sl. 0 queues (1 buckets) droptail
router# ipfw show
01002     76      8660 pipe 2 ip from any to 11.0.0.2 in
01003      0         0 pipe 3 ip from 11.0.0.2 to any out
01004      0         0 pipe 4 ip from any to 11.0.0.3 in
01005      0         0 pipe 5 ip from 11.0.0.3 to any out
01006      0         0 pipe 6 ip from any to 11.0.0.4 in
01007      0         0 pipe 7 ip from 11.0.0.4 to any out
33002     76      8660 allow ip from any to 11.0.0.2
33003      0         0 allow ip from 11.0.0.2 to any
33004      0         0 allow ip from any to 11.0.0.3
33005      0         0 allow ip from 11.0.0.3 to any
33006      0         0 allow ip from any to 11.0.0.4
33007      0         0 allow ip from 11.0.0.4 to any
65535 136273 137116246 allow ip from any to any


謝謝大家!
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP