I'm learning automation, I've set myself the goal of creating a Python script that will take a list of IP addresses and workout out what firewalls zones they are in.
( quite frankly something that should be built into the Junos CLI !! )
Input IPADDRESS >> determine interface > Determine ZONE > Output ZONE
What I want to do is really very simple but I'm getting buried in the detail in books, now i fear I cannot see the "wood for the trees" as a test I have this code
def findinterface(IPADDRESS):
print(etree.tostring(dev.rpc.get_route_information(destination='8.8.8.8'), encoding='unicode'))
interface=findinterface("8.8.8.8")
My question is very simple
this is the output how can I isolate
<via>ge-0/0/0.0</via>
so interface=ge-0/0/0.0 something like that
How can I in simplest terms pick out the individual data elements I'm interested in ?
I'm really not a programmer so after the simplest most readable solutions.
<route-information xmlns="http://xml.juniper.net/junos/12.1X44/junos-routing" xmlns:junos="http://xml.juniper.net/junos/12.1X44/junos" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><route-table><table-name>inet.0</table-name>
<destination-count>3</destination-count>
<total-route-count>3</total-route-count>
<active-route-count>3</active-route-count>
<holddown-route-count>0</holddown-route-count>
<hidden-route-count>0</hidden-route-count>
<rt style="brief"><rt-destination>0.0.0.0/0</rt-destination>
<rt-entry><active-tag>*</active-tag>
<current-active/>
<last-active/>
<protocol-name>Static</protocol-name>
<preference>5</preference>
<age seconds="4375755">7w1d 15:29:15</age>
<nh><selected-next-hop/>
<to>172.27.233.1</to>
<via>ge-0/0/0.0</via>
</nh>
</rt-entry>
</rt>
</route-table>
</route-information>
Thanks in advance
Simon Bingham
------------------------------
Simon Bingham
------------------------------