#This program gets the arp addresses for the device from jnpr.junos import Device as d from jnpr.junos.op.arp import ArpTable as at #This get the arp table dev = d(host="192.168.48.91",user='******',passwd='lab123') dev.open() arp_list = at(dev).get() # at is the short form of ArpTable at the top #Lets print out IP addresses available and ARP Entries for arp in arp_list: print("\n{} via {} has arp {}").format(arp.ip_address,arp.interface_name,arp.mac_address)
from jnpr.junos import Device as d from jnpr.junos.utils.fs import FS as fs dev = d(host='192.168.48.91',user='******',password='******') dev.open() print("Available Functions") print("-------------------") print(dir(fs(dev))) print("-------------------") print("directory usage on /var/tmp") print(fs(dev).directory_usage('/var/tmp')) print("\n")
import logging #Just to indicate warning when not connected to device. list_of_devices = ['192.168.0.81','192.168.92'] """ #First am defning the function to check the condition if > 15.1 or not, bascially i could have done without writing this but try and except block become easy in this case """ def version_check(ouptput): version = output['version'] if float((re.search(r"\d+.\d",version).group())) > 15.1 : #Basically output is a Dict and we are extracting value print("\nDevice {} is Running {} and above 15.1").format(ip,version) else: print("\nDevice {} is Running {} and below 15.1").format(ip,version) for ip in list_of_devices: device = d(host=ip, user="******", password="******") # Just to make life easier in lab try: #This helps to try the device IP and display a Error message cleanly device.open() except: print("\n") logging.warning("Error connecting to device") try: #This helps to validate if the facts were collected cleanly or not output = device.facts # Collects facts form the device version_check(output) except: print("\nError fetching output from the Device {}".format(ip))
#This program aims at getting the list of routes available on the device from jnpr.junos import Device as d from jnpr.junos.op.routes import RouteTable #Module to import Route-table #Make the connection to the device and open the device dev = d(host='192.168.0.92',user='******',password='******') dev.open() #Get the RouteTable and assign to a variable routes = RouteTable(dev).get() # Get method will help you pull the routes #Basically, you got the dictionary, the simplest way to get the routes is routes.keys() #To get the routes in the linear fashion for i in routes.keys(): print i