关于For循环的使用
今天有个需求:需要导出WLC无线控制器中所有AP的SN,试过很多命令均无法实现导出所有;
只能一个一个AP去看,灵光一闪,用For循环不是可以实现,实现代码如下:
Python
e = open('ap_sn.txt','w')
with open('d:/ap_list.txt') as f:
lines = f.read().splitlines()
a = "show ap name"
b = "inventory"
for c in lines:
#print("show ap name " + c + " inventory", file=e)
print(a,c,b,file=e)
e.close()
Powershell
$name_cn = cat d:\ap_list.txt
$a= "show ap name"
$b= "inventory"
foreach($qihao in $name_cn){
echo $a" "$qihao" "$b >>ap_sn.txt
}
将输出的结果在WLC上直接运行,运行前启动一下LOG,即可拿到结果。