进行网络运维,必须对网络拓扑情况进行详细的掌握,但是网络改动后,更新网络拓扑比较繁琐,维护人员容易懈怠,久而久之,通过人工绘制的网络拓扑很容易与现有网络出现偏差。
现在,可以通过python 丰富的库,结合CDP邻居信息,自动绘制网络拓扑信息,以下是实现思路:
1、登录设备,获取邻居信息;
工具:python(telnetlib、paramiko、netmiko库)
2、筛选需要的信息,设备本地IP,本地名称,本地接口,对端设备名称,对端接口,对端IP
工具:python(textfsm、json库)
3、根据获取进行进行画图
工具:python(N2G库)
文档说明:https://n2g.readthedocs.io/en/latest/diagram_plugins/DrawIo%20Module.html
4、调整图形。
一、通过python登录交换机设备的案例很多,在此不再赘述,各位可以在网上找到通过telnet、ssh的方式登录交换机,根据实际情况进行调整;这里后续通过telnet方式登录设备,输入show cdp nei detali 获取信息。
二、邻居信息处理
2.1获取邻居信息
输入命令后,获取交换机邻居信息如下:
1 QIA.JSJZX.JKS>show cdp nei 2 ------------------------- 3 Device ID: qia.b3.net.test.sw01 4 Entry address(es): 5 IP address: 192.17.190.225 6 Platform: cisco WS-C2960X-24TS-L, Capabilities: Switch IGMP 7 Interface: GigabitEthernet1/0/24, Port ID (outgoing port): GigabitEthernet1/0/23 8 Holdtime : 126 sec 9 10 Version : 11 Cisco IOS Software, C2960X Software (C2960X-UNIVERSALK9-M), Version 15.2(2)E6, RELEASE SOFTWARE (fc1) 12 Technical Support: http://www.cisco.com/techsupport 13 Copyright (c) 1986-2016 by Cisco Systems, Inc. 14 Compiled Fri 16-Dec-16 21:27 by prod_rel_team 15 16 advertisement version: 2 17 Protocol Hello: OUI=0x00000C, Protocol ID=0x0112; payload len=27, value=00000000FFFFFFFF010221FF000000000000F87B20311580FF0000 18 VTP Management Domain: '' 19 Native VLAN: 1 20 Duplex: full 21 Power Available TLV: 22 23 Power request id: 0, Power management id: 1, Power available: 0, Power management level: -1 24 Management address(es): 25 IP address: 192.17.190.225 26 27 ------------------------- 28 Device ID: qia.b3.net.test.sw03 29 Entry address(es): 30 IP address: 192.17.191.132 31 Platform: cisco WS-C2960S-48TD-L, Capabilities: Switch IGMP 32 Interface: GigabitEthernet1/0/23, Port ID (outgoing port): GigabitEthernet1/0/48 33 Holdtime : 134 sec 34 35 Version : 36 Cisco IOS Software, C2960S Software (C2960S-UNIVERSALK9-M), Version 12.2(55)SE7, RELEASE SOFTWARE (fc1) 37 Technical Support: http://www.cisco.com/techsupport 38 Copyright (c) 1986-2013 by Cisco Systems, Inc. 39 Compiled Mon 28-Jan-13 10:28 by prod_rel_team 40 41 advertisement version: 2 42 Protocol Hello: OUI=0x00000C, Protocol ID=0x0112; payload len=27, value=00000000FFFFFFFF010221FF000000000000B000B4865F80FF0000 43 VTP Management Domain: 'default' 44 Native VLAN: 1 45 Duplex: full 46 Power Available TLV: 47 48 Power request id: 0, Power management id: 1, Power available: 0, Power management level: -1 49 Management address(es): 50 IP address: 192.19.191.132
文章版权声明:除非注明,否则均为
譬如朝露_策温技术开发工作室博客原创文章,转载或复制请以超链接形式并注明出处。
发表评论
侧栏公告
寄语
譬如朝露博客是一个分享前端知识的网站,联系方式11523518。
热评文章
标签列表
热门文章
友情链接