我想创建一个虚拟IP值列表。可能存在一个或多个与接口关联的虚拟地址。(192.168.1.1192.168.2.1192.168.3.1)
[Switch] disp vrrp verbose interface Vlan-interface 1 | begin Virtual_IP
Virtual IP : 192.168.1.1
192.168.2.1
Master IP : 0.0.0.0
VRName :
Follow Name
[Switch] disp vrrp verbose interface Vlan-interface2 | begin Virtual_IP
Virtual IP : 192.168.3.1
Master IP : 0.0.0.0
VRName :
Follow Name :
我尝试的是首先使用.split函数和字符串“Master”作为分隔符来分割输出。然后我将使用第一个列表项,并再次使用“:”作为分隔符。第二个列表项现在包含:
192.168.1.1段 192.168.2.1 你知道吗
当我现在使用delimeter再次拆分它时,我收到三个项目 192.168.1.1 192.168.2.1和空制表符或空白
我也许可以遍历最后一个列表并“删除”空白、新行和制表符。你知道吗
这种方法好吗?有没有更好的方法来获得同样的结果?你知道吗
这个脚本可以完成任务。在本例中,文本位于测试文件中:
我用不同的方法解决了这个问题。首先捕获整个命令输出,而无需将其传输到设备本身。你知道吗
然后使用splitlines()和range,我提取了“有趣的”线。你知道吗
然后把每一行分成几个单词,检查它们的内容,有两种可能匹配,或者只有一个单词:
或者第二项包含字符串“IP”的其他项
因此,VIP列表将包含所有VIP,一个或多个。你知道吗
相关问题 更多 >
编程相关推荐