Example #1
0
def main():
    '''
    Connect to Juniper device using PyEZ. Display operational state and pkts_in, pkts_out for all
    of the interfaces.
    '''
    pwd = getpass()
    ip_addr = raw_input("Enter Juniper SRX IP: ")
    ip_addr = ip_addr.strip()

    juniper_srx = {"host": ip_addr, "user": '******', "password": pwd}

    print "\n\nConnecting to Juniper SRX...\n"
    # create device object with all the arguments in the dictionary
    a_device = Device(**juniper_srx)
    a_device.open()
    # get the ethernet port table
    eth_ports = EthPortTable(a_device)
    eth_ports.get()

    print "{:>15} {:>12} {:>12} {:>12}".format("INTF", "OPER STATE",
                                               "IN PACKETS", "OUT PACKETS")
    for intf, eth_stats in eth_ports.items():
        eth_stats = dict(eth_stats)
        oper_state = eth_stats['oper']
        pkts_in = eth_stats['rx_packets']
        pkts_out = eth_stats['tx_packets']
        print "{:>15} {:>12} {:>12} {:>12}".format(intf, oper_state, pkts_in,
                                                   pkts_out)
    print
Example #2
0
def main():
    '''
    Connect to Juniper device using PyEZ. Display operational state and pkts_in, pkts_out for all
    of the interfaces.
    '''
    pwd = getpass()
    try:
        ip_addr = raw_input("Enter Juniper SRX IP: ")
    except NameError:
        ip_addr = input("Enter Juniper SRX IP: ")
    ip_addr = ip_addr.strip()

    juniper_srx = {"host": ip_addr, "user": "******", "password": pwd}

    print("\n\nConnecting to Juniper SRX...\n")
    a_device = Device(**juniper_srx)
    a_device.open()

    eth_ports = EthPortTable(a_device)
    eth_ports.get()

    print("{:>15} {:>12} {:>12} {:>12}".format("INTF", "OPER STATE",
                                               "IN PACKETS", "OUT PACKETS"))
    for intf, eth_stats in eth_ports.items():
        eth_stats = dict(eth_stats)
        oper_state = eth_stats['oper']
        pkts_in = eth_stats['rx_packets']
        pkts_out = eth_stats['tx_packets']
        print("{:>15} {:>12} {:>12} {:>12}".format(intf, oper_state, pkts_in,
                                                   pkts_out))
    print()
Example #3
0
def main():
    '''
    Connect to Juniper device using PyEZ. Display operational state and pkts_in, pkts_out for all
    of the interfaces.
    '''
    #pwd = getpass()
    pwd = '88newclass'
    #ip_addr = raw_input("Enter Juniper SRX IP: ")
    ip_addr = '50.76.53.27'
    ip_addr = ip_addr.strip()

    juniper_srx = {
        "host": ip_addr,
        "user": "******",
        "password": pwd
    }

    print "\n\nConnecting to Juniper SRX...\n"
    a_device = Device(**juniper_srx)
    a_device.open()

    eth_ports = EthPortTable(a_device)
    eth_ports.get()

    print "{:>15} {:>12} {:>12} {:>12}".format("INTF", "OPER STATE", "IN PACKETS", "OUT PACKETS")
    for intf, eth_stats in eth_ports.items():
        eth_stats = dict(eth_stats)
        oper_state = eth_stats['oper']
        pkts_in = eth_stats['rx_packets']
        pkts_out = eth_stats['tx_packets']
        print "{:>15} {:>12} {:>12} {:>12}".format(intf, oper_state, pkts_in, pkts_out)
    print
Example #4
0
def main():

    juniper_srx = {
        "host": "184.105.247.76",
        "user": "******",
        "password": "******"
    }

    print("\n\nConnecting to Juniper SRX...\n")
    a_device = Device(**juniper_srx)
    a_device.open()

    eth_ports = EthPortTable(a_device)
    eth_ports.get()

    print("{:>15} {:>12} {:>12} {:>12}".format("INTF", "OPER STATE",
                                               "IN PACKETS", "OUT PACKETS"))
    for intf, eth_stats in eth_ports.items():
        eth_stats = dict(eth_stats)
        oper_state = eth_stats['oper']
        pkts_in = eth_stats['rx_packets']
        pkts_out = eth_stats['tx_packets']
        print("{:>15} {:>12} {:>12} {:>12}".format(intf, oper_state, pkts_in,
                                                   pkts_out))
    print()
Example #5
0
def main():
    '''
    For each of the SRX's interfaces, display: the operational state,
    packets-in, and packets-out. You will probably want to use EthPortTable for
    this.
    '''
    pwd = getpass()
    try:
        a_device = Device(host='184.105.247.76', user='******', password=pwd)
        a_device.open()
        ports = EthPortTable(a_device)
        ports.get()
        print "\n"*2
        for port, port_att in ports.items():
            print "#"*80
            print "Operational state, Packets-in and Packets-out for Port {0} are :".format(port)
            print "#"*80
            for desc, value in port_att:
                if desc in ['oper', 'rx_packets', 'tx_packets']:
                    print " {0}: {1}".format(desc, value)
            print "*"*80
            print "\n"*2
        print
    except:
        print
        print "Authentication Error"
        print
Example #6
0
def main():
    password = getpass()
    device = Device(host = '184.105.247.76', user = '******', password = password)
    
    device.open()
    eth = EthPortTable(device)
    eth.get()
    
    for interface,v in eth.items():
        if interface == "fe-0/0/7":
            print "interface {}".format(interface)
            for field, value in v:
                if 'bytes' in field:
                    print "{} equals {}".format(field, value)
Example #7
0
def main():
    """Using Juniper's pyez for get interface operations."""
    password = getpass()
    a_device = Device(host='184.105.247.76', user='******', password=password)
    a_device.open()

    eth = EthPortTable(a_device)
    eth.get()
    print
    for intf, v in eth.items():
        if intf == 'fe-0/0/7':
            print 'intf {}: '.format(intf)
            for field_name, field_value in v:
                if 'bytes' in field_name:
                    print "    {:<15} {:<30}".format(field_name, field_value)
    print
Example #8
0
def main():

    pwd = getpass()

    juniper = {
        "host": "50.76.53.27",
        "user": "******",
        "password": pwd
    }

    a_device = Device(**juniper)
    a_device.open()

    ports = EthPortTable(a_device)
    ports.get()

    for eth, stats in ports.items():
        stats = dict(stats)
        #print stats
        interface_status = stats['oper']
        packets_in = stats['rx_packets']
        packets_out = stats['tx_packets']
        print "Interface: %s Interface status: %s In Packets: %s Out Packets: %s" % (eth, interface_status, packets_in, packets_out)
Example #9
0
def main():
    pwd = getpass()

    a_device = Device(host='184.105.247.76', user=USER, password=pwd)
    a_device.open()

    ports = EthPortTable(a_device)
    ports.get()

    print
    print "{:<20} {:<10} {:>20} {:>20}".format('interface', 'state',
                                               'RX packets', 'TX packets')
    for intfc, tuple_list in ports.items():
        for info, stat in tuple_list:
            if info == 'oper':
                oper = stat
            elif info == 'rx_packets':
                rx_packets = stat
            elif info == 'tx_packets':
                tx_packets = stat
        print "{:<20} {:<10} {:>20} {:>20}".format(intfc, oper, rx_packets,
                                                   tx_packets)

    print
Example #10
0
from jnpr.junos import Device
from jnpr.junos.op.ethport import EthPortTable
from getpass import getpass
from pprint import pprint
import ipdb

a_device = Device(host="srx2.lasthop.io", user="******", password=getpass())
a_device.open()

ipdb.set_trace()
ports = EthPortTable(a_device)
ports.get()

print(ports)
print(ports.keys())
pprint(ports.values())
pprint(ports.items())
Example #11
0
def juniper_print(k, v):
    print
    print k
    print '-' * 20
    pprint(v)
    print '-' * 20


a_device = Device(**juniper_srx)
a_device.open()

eth_ports = EthPortTable(a_device)
eth_ports.get()
print '-' * 80
print "Ethernet Ports"
for k, v in eth_ports.items():
    juniper_print(k, v)
print '-' * 80
raw_input("Hit enter to continue: ")

arp = ArpTable(a_device)
arp.get()
print '-' * 80
print "ARP"
for k, v in arp.items():
    juniper_print(k, v)
print '-' * 80
raw_input("Hit enter to continue: ")

lldp = LLDPNeighborTable(a_device)
lldp.get()
Example #12
0
from pprint import pprint



pwd = getpass()
a_device = Device(host='50.242.94.227', user='******', password=pwd)
a_device.open()
pprint(a_device.facts)



ports = EthPortTable(a_device)
ports.get()
ports.keys()

ports.items()
ports.values()

ports['fe-0/0/1']
ports['fe-0/0/1'].items()
for k,v in ports['fe-0/0/1'].items():
	print k, v

ports['fe-0/0/1']['oper']
ports['fe-0/0/1']['macaddr']



from jnpr.junos.op.arp import ArpTable
arp_entries = ArpTable(a_device)
arp_entries.get()
Example #13
0
print "\nLLDP Get"
print '-' * 50
lldp = LLDPNeighborTable(a_device)
lldp.get()

for k, v in lldp.items():
    print k
    for entry in v:
        print entry

#### Getter operations
print "\nEth Port Get"
print '-' * 50
eth = EthPortTable(a_device)
eth.get()
pprint(eth.items())

#### Getter operations
print "\nRoute Table Get"
print '-' * 50
z_routes = RouteTable(a_device)
z_routes.get()
pprint(z_routes.items())

#### Config operations
print
print "Current static routes"
print '-' * 50
pprint(z_routes.keys())
print