0

i m working on a project at school. i m asked to translate a juniper firewall configuration file to another firewall syntax. My problem here is transforming the juniper conf file to a dictionary so i can work on it

i Tried spliting the text by "{" and "}" and bunch of different things, but doesn't seem to help

    family inet {
        replace:
        /*
        ** $Id:$
        ** $Date:$
        ** $Revision:$
        **
        */
        filter bridge {
            interface-specific;
            term rule100 {
                from {
                    source-address {
                        10.0.0.1/32;
                    }
                    destination-address {
                        10.0.0.1/32;
                    }
                    protocol tcp;
                    destination-port 80;
                }
                then {
                    discard;
                }
            }
      }
    }
}

i expect a python dictionary like this

dic = { "term rule100" : {
                "from" :{
                    "source-address" : "10.0.0.1/32;",
                    "destination-address" : "10.0.0.1/32;",
                    "protocol" :"tcp;", "destination-port" : "80;",
                    "then" : "discard;"
                },
            }
}

1 Answers1

-1

I had similar problem at my work to show the configured values in a nice formatted UI and to get the latest configuration, I ran the CLI commands using with "display xml" format. E.g. show configuration security zones | display xml

This returns the output in nice xml format, which can be then read using various XML readers.

You can also use "display json" option which returns the output in json format.

Amit Ravi
  • 1
  • 2