Exemple #1
0
async def get_interface(ctx, arg1, interface):

    net_connect = Netmiko(host=arg1,
                          username="******",
                          password="******",
                          device_type="cisco_ios")

    output = net_connect.send_command_expect("show ip interface brief",
                                             use_genie=True)
    parsed = output["interface"][interface]["ip_address"]

    net_connect.disconnect()
    await ctx.send(parsed)
Exemple #2
0
async def get_interface_status(ctx, arg1):

    net_connect = Netmiko(host=arg1,
                          username="******",
                          password="******",
                          device_type="cisco_ios")
    parsed = ""
    output = net_connect.send_command_expect("show ip interface brief",
                                             use_genie=True)
    for n in output["interface"]:
        status = output["interface"][n]["status"]
        parsed += n + " = " + status + "\n"

    net_connect.disconnect()

    await ctx.send(parsed)
            vlanNumber = input(
                '\nPlease assign VLAN number: ')  # User enters VLAN number
            showVlan = net_connect.send_command(
                '\nshow vlan brief'
            )  # Store variable if user does not execute menu option1
            if vlanNumber in showVlan:  # Checks for valid vlan
                print('\nAssiging VLAN number...')
                config_commands = [  # config_commands list array.
                    'Interface ' + interface,
                    'switchport access vlan ' + vlanNumber
                ]
                net_connect.send_config_set(config_commands)
                print('\nVlan Updated...')
                print('\nShowing Updated Configuration')
                output = net_connect.send_command(
                    'show run int ' +
                    interface)  # Show Updated Config after changes
                print(output)
                print('\nWriting Configuration...')
                net_connect.send_command_expect('write mem')  # Write Mem
            else:
                print('******ERROR: INVALID VLAN CHOICE******')
                continue
# Ending VLAN configuration
    elif menuChoice == '4':
        exitProgram()
        break
    else:
        # Any integer inputs other than values 1-4 print an error message
        print("\nInvalid option. Enter any key to try again..")
    "username": "******",
    "password": passwd,
    "device_type": "cisco_ios",
}


def append_doc(file_name, varable):
    f = open(file_name, 'a')
    f.write(varable)
    f.write('\n')
    f.close()


def write_doc(file_name, varable):
    f = open(file_name, 'w')
    f.write(varable)
    f.close()


file_name = "results.csv"
write_doc(file_name, "")

for router in (cisco1, cisco2, cisco3):
    net_connect = Netmiko(**router)
    print(net_connect.find_prompt())
    output = net_connect.send_command_expect('show ver | i .bin')
    for each_word in output.split(" "):
        if ".bin" in each_word:
            ver = each_word
    results = router + "," + ver
    append_doc(file_name, results)
Exemple #5
0
device2 = {
    "ip": "10.91.240.11",
    "username": "******",
    "password": "******",
    "device_type": "versa",
}

commands = "move devices device CPE11-HKG-HYBRD-IPC00190 config orgs org-services IPC00190 class-of-service qos-policies Default-Policy rules LAN1-VRF-Internet-Default jkjkjk"

cmd2 = "show orgs org IPC00190 sessions sdwan detail | nomore| select source-port 2000"
net_connect = Netmiko(**device2)

print()
print(net_connect.find_prompt())
# print(net_connect.config_mode(config_command="configure private"))
# print(net_connect.check_config_mode())
# output = net_connect.send_config_set(commands, exit_config_mode=True, cmd_verify=False)
# output = net_connect.send_command_expect(commands, expect_string='%', strip_prompt=False, strip_command=False, cmd_verify=True)
# print(output)
# output += net_connect.commit(and_quit=True)
output = net_connect.send_command_expect(cmd2,
                                         expect_string='>',
                                         strip_prompt=True)
print(net_connect.global_cmd_verify)
print(output)
# print(net_connect.exit_config_mode())
# print(net_connect.check_config_mode())
# print(output)
print(net_connect.find_prompt())
net_connect.disconnect()