Ejemplo n.º 1
0
def main():
    pynet_rtr1 = dict(ip='50.242.94.227',
                      username='******',
                      password='******',
                      pin_file='pynet-rtr1-pin.txt',
                      port=15002)

    pynet_rtr2 = dict(ip='50.242.94.227',
                      username='******',
                      password='******',
                      pin_file='pynet-rtr2-pin.txt',
                      port=8002)

    for a_rtr in (pynet_rtr1, pynet_rtr2):
        rtr_obj = NetworkDevice(**a_rtr)
        rtr_obj.establish_session()

        vty_service = VtyService(rtr_obj.net_element)
        vty_service.open()

        router_name = rtr_name = rtr_obj.net_element.properties.sys_name

        cmd = "show version"
        cli = vty_service.write(cmd)

        print rtr_name
        print cli

        rtr_obj.disconnect()
Ejemplo n.º 2
0
def main():
    '''
    Using onePK and the VTY Service obtain the output from the 'show version'
    command.  Use 'terminal length 0' to disable output paging (i.e. disable
    '--More--' prompting).
    '''

    pynet_rtr1 = dict(
        ip='10.10.10.10',
        username='******',
        password='******',
        pin_file='pynet-rtr1-pin.txt',
        port=15002
    )

    pynet_rtr2 = dict(
        ip='10.10.10.10',
        username='******',
        password='******',
        pin_file='pynet-rtr2-pin.txt',
        port=8002
    )

    for a_rtr in (pynet_rtr1, pynet_rtr2):

        rtr_obj = NetworkDevice(**a_rtr)
        rtr_obj.establish_session()

        rtr_name = rtr_obj.net_element.properties.sys_name

        vty_service = VtyService(rtr_obj.net_element)
        vty_service.open()

        cmd = "terminal length 0"
        cli = vty_service.write(cmd)
        cmd = "show version"
        cli = vty_service.write(cmd)

        print "\n" + "*" * 80
        print "** CONNECTED TO: {}".format(rtr_name)
        print "*" * 80
        print cli
        print "*" * 80
        print "\n\n"

        rtr_obj.disconnect()
def main():
    '''
    Using onePK and the VTY Service obtain the output from the 'show version'
    command.  Use 'terminal length 0' to disable output paging (i.e. disable
    '--More--' prompting).
    '''

    pynet_rtr1 = dict(ip='10.10.10.10',
                      username='******',
                      password='******',
                      pin_file='pynet-rtr1-pin.txt',
                      port=15002)

    pynet_rtr2 = dict(ip='10.10.10.10',
                      username='******',
                      password='******',
                      pin_file='pynet-rtr2-pin.txt',
                      port=8002)

    for a_rtr in (pynet_rtr1, pynet_rtr2):

        rtr_obj = NetworkDevice(**a_rtr)
        rtr_obj.establish_session()

        rtr_name = rtr_obj.net_element.properties.sys_name

        vty_service = VtyService(rtr_obj.net_element)
        vty_service.open()

        cmd = "terminal length 0"
        cli = vty_service.write(cmd)
        cmd = "show version"
        cli = vty_service.write(cmd)

        print "\n" + "*" * 80
        print "** CONNECTED TO: {}".format(rtr_name)
        print "*" * 80
        print cli
        print "*" * 80
        print "\n\n"

        rtr_obj.disconnect()
Ejemplo n.º 4
0
def main():

    pynet_rtr1 = dict(
        ip = '10.10.10.10',
        username = '******',
        password = '******',
        pin_file = 'pynet-rtr1-pin.txt',
        port = 15002
    )

    pynet_rtr2 = dict(
        ip = '10.10.10.10',
        username = '******',
        password = '******',
        pin_file = 'pynet-rtr2-pin.txt',
        port = 8002
    )

    for a_rtr in (pynet_rtr1, pynet_rtr2):

        rtr_obj = NetworkDevice(**a_rtr)
        rtr_obj.establish_session()

        rtr_name = rtr_obj.net_element.properties.sys_name

        vty_service = VtyService(rtr_obj.net_element)
        vty_service.open()

        CMD = "terminal length 0"
        cli = vty_service.write(CMD)
        CMD = "show version"
        cli = vty_service.write(CMD)

        print "\n" + "*" * 80
        print "** CONNECTED TO: {}".format(rtr_name)
        print "*" * 80
        print cli
        print "*" * 80
        print "\n\n"

        rtr_obj.disconnect()
Ejemplo n.º 5
0
    def handle_event(self, event, clientData):

        print "-----"
        print "Caught: " + event.message
        print "-----"

        blackhole = False

        vtyService = VtyService(router)
        vtyService.open()
        TEST_CMD1 = "who"
        cli_result = vtyService.write(TEST_CMD1)
        vtyService.close()
        victim_string = " " + victim + " "

        lines = cli_result.split("\n")
        for line in lines:
            if " vty " and victim_string in line:
                print "-----"
                print "User is on the system: " + victim
                entries = line.split()
                for entry in entries:
                    if is_ip_address(entry):
                        blackhole = True
                        blackhole_ip = entry

        if blackhole:
            print "Blackholing ip: " + blackhole_ip
            out_if = router.get_interface_by_name("Null0")

            routing = Routing.get_instance(router)
            approutetable = routing.app_route_table
            route_scope = L3UnicastScope("", L3UnicastScope.AFIType.IPV4,
                                         L3UnicastScope.SAFIType.UNICAST, "")
            aL3UnicastNextHop = L3UnicastNextHop(out_if, "")

            aL3UnicastNextHopList = list()
            aL3UnicastNextHopList.append(aL3UnicastNextHop)

            destNetworkPrefix = NetworkPrefix(blackhole_ip, 32)

            aRoute = L3UnicastRoute(destNetworkPrefix, aL3UnicastNextHopList)
            aRoute.admin_distance = 1

            routeOperation = L3UnicastRouteOperation(0, aRoute)

            routeOperationList = list()
            routeOperationList.append(routeOperation)
            mylist = approutetable.update_routes(route_scope,
                                                 routeOperationList)
        print "-----"
        print "Type a key to exit script"
Ejemplo n.º 6
0
Archivo: 6-3.py Proyecto: sfromm/pyn
def main(args):
    ''' main '''
    rtrs = yaml.load(file(args[0]).read())
    for rtr in rtrs:
        ndev = NetworkDevice(**rtr)
        ndev.connect()

        print "Connection established to: %s" % ndev.net_element.properties.sys_name
        vty_svc = VtyService(ndev.net_element)
        vty_svc.open()
        for cmd in CMDS:
            out = vty_svc.write(cmd)
            print out

        ndev.disconnect()
Ejemplo n.º 7
0
 def check_target(self):
     logger.info("******* CHECKING MEDIATRACE CONFIG *******")
     try:
         vty = VtyService(self.get_network_element())
         vty.open()
         resp = vty.write('sho run')
         resping = vty.write('ping '+ self.dst_ip)
         vty.close()
         if resp:
             vty.open()
             if resp.find('mediatrace initiator source-ip') == -1:
                 logger.info('"mediatrace initiator ..." not set on target')
                 logger.info("******* ADDING INITIATOR SOURCE *******")
                 vty.write('conf t')
                 vty.write('mediatrace initiator source-ip '+ self.initiater_src)
             if resp.find('mediatrace responder') == -1:
                 logger.info('"mediatrace responder" not set on target ')
                 logger.info("******* ADDING RESPONDER *******")
                 vty.write('conf t)
                 vty.write('mediatrace responder')
             if resp.find('service set mediatrace') > -1:
                 if resping.find('Success rate is 0') > -1:
                     logger.info('Target cannot reach %s so ECHO '
                                 'traceroute_status will TIMEOUT',
                                 self.dst_ip)
                 return True
         raise Exception('forced fail')
     except Exception as e:
         logger.info("Target not setup correctly")
         res = raw_input('''
             Target test device must have the following configurations:
             -------------------------------------------------------------------
             |conf t                                                           |
             | mediatrace responder                                            |
             | mediatrace initiator source-ip <IP address of Target interface> |
             | onep                                                            |
             |  service set mediatrace                                         |
             -------------------------------------------------------------------
             Enter yes if config has been applied or quit to exit: 
             ''')
         if res.startswith('y'):
             return self.check_target()
         else:
             return False
     return True
Ejemplo n.º 8
0
 """Get a VTYService from the NE"""
 #  START SNIPPET: create_vty
 vtyService = VtyService(tutorial.get_network_element())
 #  END SNIPPET: create_vty
 """Open the VTY on the NE with the default command interpreter"""
 #  START SNIPPET: open_vty
 vtyService.open()
 #  END SNIPPET: open_vty
 """Get a timeout of the VTY on NE"""
 #  START SNIPPET: get_vty_timeout
 logger.info("VTY Time Out - %s", vtyService.timeout)
 #  END SNIPPET: get_vty_timeout
 """Write a string to the VTY on NE"""
 #  START SNIPPET: write_vty_command
 TEST_CMD1 = "show onep status"
 cli_result = vtyService.write(TEST_CMD1)
 logger.info("Test Command : %s", TEST_CMD1)
 logger.info("CLI Result for Test Command : %s", cli_result)
 #  END SNIPPET: write_vty_command
 """Get the parser state and its attributes"""
 try:
     #  START SNIPPET: get_vty_parser_state
     parser_state = vtyService.get_parser_state()
     #  END SNIPPET: get_vty_parser_state
     """Show the parser state attributes"""
     tutorial.show_parser_state_attributes(parser_state)
 except OnepRemoteProcedureException as re:
     logger.error("Error in getting parser state : ", re)
 """Get the VTY State"""
 #  START SNIPPET: get_vty_state
 logger.info("State - %s", vtyService.state)
Ejemplo n.º 9
0
            commandList+=str(i+1)+" deny ip any "+configureIP+" 0.0.0.0\n"
            i+=1
        # clear all entries at the end of the ACL
        while i<maxACLLines:
            commandList+="no "+str(i+1)+"\n"
            i+=1
        commandList+=str(maxACLLines+1)+" permit any any\n"

        ne_vty=VtyService(ne)

        try:
            ne_vty.open()
        except:
            print("ERROR: Couldn't connect to VtyService "+ne.host_address)
        else:
            cli_result=ne_vty.write(commandList)

            ne_vty.close()
            ne.disconnect()

    #print the ACL to screen for visual check
    
    # ------ START - remove this for production -------
    print("ip access-list extended "+aclName)

    i=0
    for printIP in resolvedIPs:
        print(str(i+1)+" deny ip any "+printIP+" 0.0.0.0")
        i+=1
    while i<maxACLLines:
        print("no "+str(i+1))