在系统运维中,检测route能添加多少条?
可以用python实现一个脚本,在后台循环执行命令,做成一个通用的程序,可以添加多条规则。
使用方法,在程序所在目录添加建立一个command.txt文件,在文件中输入需要添加规则的格式。
注意,其中的目的IP地址使用字符串dip来代替,拿route为例,需要在command.txt中添加:
route add -net dip netmask 255.255.255.255 gw 118.8.8.1
然后,运行docommand.py脚本。
docommand.py脚本的内容,如下:
 
#!/usr/bin/python 
#filename:docommand.py 
import os
#从文件中读取命令模板
f=file('command.txt') 
line=f.readline() 
print line 
f.close()
#取出dip前后字符串
alist=line.split("dip") 
print alist[0] 
print alist[1]
#替换dip,执行命令
for i in range(1,254): 
    for j in range(1,254): 
     iamcommand=alist[0]+str(i)+'.'+str(j)+'.1.1'+alist[1] 
     print iamcommand 
     os.system(iamcommand)