Parsing firewall policies using Python

  1. Create a python list and store regex patterns created earlier in it
Code to store list of dictionaries. Each dictionary is a firewall rule
code fills missing key features with a default value
  1. Load address-book text file (I also replaced subnet mask 255.255.255.255 format to /32 to make look prettier) into one big dictionary in which key is the name of address-books and value are subnets against them
  2. Capture source and destination address-books from each rule dictionary and in try block extract IPs from address-book by parsing address-book name as dictionary key we got from step 1 and store in a list. And if an exception occurs, store dictionary key as a value in the list. Convert each entry of list(data type is a list of list) from list to string and update the dictionary values
extract subnet for address-book part1
extract subnet for address-book part2

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store