def work_router(action, session, intf, tftp_ip, cfg_file, ip, mask, gw): # establish session rtr = pysession(session=session) rtr.send(''' enable conf term int %s ip addre %s %s enable exit ip route %s 255.255.255.255 %s end ''' % (intf, ip, mask, tftp_ip, gw) ) if action == 'reload': cmd = 'copy tftp startup-config %s %s' % (tftp_ip, cfg_file) rtr.send(cmd) time.sleep(5) rtr.send('reload') elif action == 'save': cmd = 'copy run tftp %s %s' % (tftp_ip, cfg_file) rtr.send(cmd)
def reload_brcd_ni(session='', tftp_ip='', cfg_file='', ip='', mask='', gw=''): rtr = pysession(session=session) if ip != '': rtr.send(''' enable conf term int management 1 ip addre %s/%s exit ip route %s 255.255.255.255 %s end ''' % (ip, mask, tftp_ip, gw)) rtr.send('copy tftp startup-config %s %s' % (tftp_ip, cfg_file)) time.sleep(5) rtr.send('reload')
sys.exit(2) session, cfg_file = "", "" # parse the sys.argv for opt, arg in opts: if opt in ("-h", "--help"): usage() elif opt in ("-c", "--cfgfile"): cfg_file = arg elif opt in ("-s", "--session"): session = arg if session == "" or cfg_file == "": usage() sys.exit(2) try: with open(cfg_file, "r") as f: lines = f.readlines() except IOError: print "Failed to open config file, exit......" sys.exit(1) rtr = pysession(session=session) for line in lines: line = line.strip() rtr.send(line)
print ''' ############################################################################### # # # Brocade Data Collection Tool # # ver 0.1 # # # # Author: [email protected] # # # ############################################################################### ''' issue_dest = raw_input('please provide the dest ip of issue prefix: ') # get the session info interactively cer = pysession() #cer = pysession(session='telnet 10.18.24.78') cer.pprint=True # Part 0. basic info o = cer.send("show ip route %s" % issue_dest) dummy, issue_prefix, next_hop, oif, cost, prefix_type, prefix_uptime, vrf\ = parse_sh_ip_route_prefix(o)[:8] # get netmask in dot notation issue_prefix, net_mask = issue_prefix.split('/') net_mask_dot = netmask_to_dot_notation(net_mask) print '\n' + pys_lib.pline2('Basic Prefix Info')
print_header() print '\n' + PYSLib.pline1('SESSION INFO') print "Session: %s" % session print "User ID: %s" % userid print PYSLib.pline1('Press Enter to continue ......') dummy = raw_input("") print '\n' + PYSLib.pline1('LIST OF COMMANDS') print all_commands print PYSLib.pline1('Press Enter to start......') dummy = raw_input("") router = pysession(session=session, user=userid, password=password, enable_password=enable_password, log_file_prefix='brcd__', output_file=output_file) router.pprint=True router.send(all_commands) total_sec = int(time.time() - router.start_time) elapse_time = '%d min %d sec' % (total_sec/60, total_sec%60) sleep_time = '%d min %d sec' % (router.sleep_time/60, router.sleep_time%60) file_size_in_KB = '%d KB' % int(os.stat(router.log_file_name).st_size/1000) print '\n' + PYSLib.pline2('DATA COLLECTION SUMMARY') print ' script running time :', elapse_time
elif opt in ('-s', '--session'): session = arg elif opt in ('-u', '--user'): user = arg elif opt in ('-p', '--password'): password = arg elif opt in ('-e', '--enable'): enable_password = arg elif opt in ('-o', '--output'): outfile = arg if session == '': usage() sys.exit(2) rtr = pysession(session=session, user=user, password=password, enable_password=enable_password, output_file=outfile) total_attack = 0 while True: attacked = False attacked_int = [] o = rtr.send('show stat %s | inc PO|InUti' % ' '.join(monitor_ports)) for item in parse_stat(o): p, i, o = item if i > attack_bw_pert: attacked_int.append(p) attacked = True if attacked: