1

New to programming with python as my first language.

I'm attempting to create a regex that would match 'lo0.0' or any other interface that presents in that position from the string below. I need the ip address '192.168.50.5' to be input as a variable so the regex can be reused dynamically as part of a loop which will ensure that the interface retrieved is the correct outgoing interface for that route.

I've attempted to use positive lookbehind assertions but I haven't had much success in getting the script to take a variable at the start of the regex but within the lookbehind assertion using either dotall or multiline.

'\n\ninet.0: 13 destinations, 14 routes (13 active, 0 holddown, 0 hidden)\n+ = Active Route, - = Last Active, * = Both\n\n192.168.50.5/32 *[Direct/0] 1w2d 02:39:35\n > via lo0.0\n'

Chromacy
  • 21
  • 4
  • This is output of which command? Have you checked if there is structured output using `| display json` or `| display xml`? – Shashank V Jan 15 '20 at 18:09
  • Why are you doing screen scrapping when the o/p of the command you are using got structured o/p in XML and JSON format? you can use PyEZ or ncclient in place of netmiko for that case. Are you trying to define TextFSM template? – Nitin Kr Jan 16 '20 at 04:19
  • Thanks for the suggestions guys, honestly this is my first time building a script for something practical after learning python so wasn't aware of the xml/json displays. the command sent was 'show route variable_containing_ip'. For work reasons I have to keep the amount of python packages down unfortunately hence just the focus on using netmiko as we've got a large spread of different vendors. I'll give the xml format a go and see how it goes. . Thank – Chromacy Jan 16 '20 at 11:10

1 Answers1

1

Using display xml solved my issue, the xml outputs with a match in the original junos command made it much easier to parse with a regex. Cheers Shashank

Chromacy
  • 21
  • 4