def get_running_config(chan, enable_password): """ captures the running config :param chan: ssh channel :param enable_password: enable password :return: running config """ # sends 'show running-config' to device running_config = send_command('skip', 'sh run', read=True, chan=chan) time.sleep(2) # Capture only running config data running_config = re.findall(r'!\r\nver.*end', running_config, re.S).pop() # Parses config running_config = CiscoConfParse(running_config.splitlines()) print("Download complete") return running_config
! neighbor 10.220.88.20 remote-as 42 description pynet-rtr1 address-family ipv4 unicast route-policy ALLOW in route-policy ALLOW out ! ! neighbor 10.220.88.32 remote-as 43 address-family ipv4 unicast route-policy ALLOW in route-policy ALLOW out """ config = CiscoConfParse(config.splitlines()) bgp_neighbors = config.find_objects_w_parents(parentspec=r"^router bgp", childspec=r"^\s+neighbor") bgp_peers = [] for neighbor in bgp_neighbors: neighbor_ip = neighbor.text.split()[1] for line in neighbor.children: if "remote-as" in line.text: neighbor_as = line.text.split()[1] bgp_peers.append((neighbor_ip, neighbor_as)) print("BGP Peers:") print(bgp_peers)