• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python netmiko.ConnectHandler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中netmiko.ConnectHandler的典型用法代码示例。如果您正苦于以下问题:Python ConnectHandler类的具体用法?Python ConnectHandler怎么用?Python ConnectHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ConnectHandler类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: main

def main():
    for device in rtr_list:
        rtr_conn = ConnectHandler(**device)
        prompt = rtr_conn.find_prompt()
        rtr_conn.config_mode()
        output = rtr_conn.send_config_from_file(config_file='4_8_cfg.txt')
        print output
开发者ID:ssherman68,项目名称:PyNetAutoClass,代码行数:7,代码来源:4-8.py


示例2: main

def main():
    ip_addr = '50.76.53.27'
    port_rtr1 = 22
    port_rtr2 = 8022
    username = 'pyclass'
    password = '88newclass'
    #password = getpass()

    pynet1 = {
        'device_type': 'cisco_ios',
        'ip': ip_addr,
        'username': username,
        'password': password,
        'port': port_rtr1,
    }


    pynet2 = {
        'device_type': 'cisco_ios',
        'ip': ip_addr,
        'username': username,
        'password': password,
        'port': port_rtr2,
    }


    pynet_rtr1 = ConnectHandler(**pynet1)
    pynet_rtr2 = ConnectHandler(**pynet2)

    out1 = pynet_rtr1.send_config_from_file(config_file='w4-8-commands.txt')
    out2 = pynet_rtr2.send_config_from_file(config_file='w4-8-commands.txt')

    print "The output in rtr1 is:\n%s\n" % out1
    print "The output in rtr2 is:\n%s\n" % out2
开发者ID:thomarite,项目名称:pynetw4,代码行数:34,代码来源:w4-8.py


示例3: __init__

class Router:
    def __init__(self):
        self.net_connect = ConnectHandler(**homeRTR)

    def show_dhcp_binding(self, mac_end):
        command = 'show ip dhcp binding | incl ' + mac_end
        output = self.net_connect.send_command(command)
#        self.net_connect.disconnect()
        return output.split('\n')

    def ping_ipaddr(self, ipaddr):
        command = 'ping ' + ipaddr
        output = self.net_connect.send_command(command)
#        self.net_connect.disconnect()
        return output.split('\n')

    def show_arp(self, mac_end):
        command = 'show arp | incl ' + mac_end
        output = self.net_connect.send_command(command)
#        self.net_connect.disconnect()
        return output.split('\n')

    def add_dhcp_client(self, config_list):
        output = self.net_connect.send_config_set(config_list)
        return output.split('\n')

    def delete_dhcp_client(self, config_list):
        output = self.net_connect.send_config_set(config_list)
        return output.split('\n')
开发者ID:astianseb,项目名称:sgdhcpmanager-sb2admin,代码行数:29,代码来源:helperfunctions.py


示例4: connect_net_device

def connect_net_device(**kwarg):
    net_connect = ConnectHandler(**kwarg)
    print "Current prompt: {}".format(net_connect.find_prompt())
    show_run = net_connect.send_command("sh run")
    print "sh run output: \n\n{}".format(show_run)
    filename = net_connect.base_prompt + ".txt"
    save_file (filename , show_run)
开发者ID:aniketpuranik,项目名称:pynet_test,代码行数:7,代码来源:ex25_Netmiko.py


示例5: main

def main():

    router1 = {
        'device_type': 'cisco_ios',
        'ip': '10.9.0.67',
        'username': 'myuser',
        'password': 'mypass'
    }

    router2 = {
        'device_type': 'cisco_ios',
        'ip': '10.63.176.57',
        'username': 'myuser',
        'password': 'mypass'
    }

    routers = [router1, router2]

    for router in routers:

        # Connect to device
        device_conn = ConnectHandler(**router)

        # Print arp table
        print device_conn.send_command("show arp")
        print "\n\n"

        # Close connection
        device_conn.disconnect()
开发者ID:ande0581,项目名称:pynet,代码行数:29,代码来源:class4_ex6.py


示例6: main

def main():
    """
    Write a Python script that retrieves all of the network devices from the database
    Using this data, make a Netmiko connection to each device.
    Retrieve 'show run'.
    Record the time that the program takes to execute.
    """
    start_time = datetime.now()
    django.setup()
    my_devices = NetworkDevice.objects.all()
    print
    for a_device in my_devices:
        a_device_netmiko = create_netmiko_dict(a_device)
        remote_conn = ConnectHandler(**a_device_netmiko)
        if 'juniper' in a_device.device_type:
            show_run = remote_conn.send_command_expect("show configuration")
        else:
            show_run = remote_conn.send_command_expect("show run")
        print a_device.device_name
        print '-' * 80
        print show_run
        print '-' * 80
        print
    print ">>>>>>>> Total Time: {}".format(datetime.now() - start_time)
    print
开发者ID:duncanbarter,项目名称:pynet_ons,代码行数:25,代码来源:ex35_django.py


示例7: main

def main():
    for device in rtr_list:
        rtr_conn = ConnectHandler(**device)
        output = rtr_conn.send_command("show arp")
        print device['ip'], " ARP Table:\n"
        print "==========================================================="
        print output, "\n"
开发者ID:ssherman68,项目名称:PyNetAutoClass,代码行数:7,代码来源:4-6.py


示例8: main

def main():
    """Exercises using Netmiko"""
    rtr1_pass = getpass("Enter router password: ")
    sw1_pass = getpass("Enter switch password: ")
    pynet_rtr1 = {
        'device_type': 'cisco_ios',
        'ip':   '184.105.247.70',
        'username': 'pyclass',
        'password': rtr1_pass,
    }

    pynet_sw1 = {
        'device_type': 'arista_eos',
        'ip':   '184.105.247.72',
        'username': 'admin1',
        'password': sw1_pass,
    }

    for a_device in (pynet_rtr1, pynet_sw1):
        net_connect = ConnectHandler(**a_device)
        print "Current Prompt: " + net_connect.find_prompt()

        show_arp = net_connect.send_command("show arp")
        print
        print '#' * 80
        print show_arp
        print '#' * 80
        print

        show_run = net_connect.send_command("show run")
        filename = net_connect.base_prompt + ".txt"
        print "Save show run output: {}\n".format(filename)
        save_file(filename, show_run)
开发者ID:andylinjefferson,项目名称:pynet_ons,代码行数:33,代码来源:ex25_netmiko.py


示例9: main

def main():
    django.setup()
    
    start_time = datetime.now()
    devices = NetworkDevice.objects.all()
    credentials = Credentials.objects.all()
    
    for a_device in devices:
        print "\n", a_device
        device_type = a_device.device_type
        port = a_device.port
        secret = ''
        ip = a_device.ip_address
        creds = a_device.credentials
        username = creds.username
        password = creds.password
        remote_conn = ConnectHandler(device_type=device_type, ip=ip, username=username, password=password, port=port, secret=secret)
        
        print "#" * 50
        print remote_conn.send_command("show arp")
        print "#" * 50
        pass

    elapsed_time = datetime.now() - start_time
    print "Elapsed time: {}".format(elapsed_time)
开发者ID:brutalic,项目名称:pynet_brutal,代码行数:25,代码来源:vid-6-concur.py


示例10: main

def main():
    #password = getpass()
    password = '88newclass'

    # Define libraries for devices we will connect to
    pynet1 = {
        'device_type': 'cisco_ios',
        'ip': '50.76.53.27',
        'username': 'pyclass',
        'password': password,
        'port': 22,
    }
    pynet2 = {
        'device_type': 'cisco_ios',
        'ip': '50.76.53.27',
        'username': 'pyclass',
        'password': password,
        'port': 8022,
    }
    srx = {
        'device_type': 'juniper',
        'ip': '50.76.53.27',
        'username': 'pyclass',
        'password': password,
        'port': 9822,
    }


    pynet_rtr2 = ConnectHandler(**pynet2)
    pynet_rtr2.config_mode()
    outp = pynet_rtr2.find_prompt()
    print outp
    outp2 = pynet_rtr2.check_config_mode()
    print 'Config mode status is ' + str(outp2)
开发者ID:swackhap,项目名称:pynet_python_class,代码行数:34,代码来源:netmiko_test1.py


示例11: main

def main():
    print 'Username:',
    usern = raw_input()
    passwd = getpass()

    for i in range(len(DEVICES)):
        try:
            net_dev = {
                        'device_type':DEV_TYPE[i],
                        'ip':DEVICES[i],
                        'username':usern,
                        'password':passwd
                    }

            print '>>>>>>>>>>>>> DEVICE: {} <<<<<<<<<<<<<<'.format(DEVICES[i])
            # Initiating netmiko connection
            net_connect = ConnectHandler(**net_dev)
            resp = net_connect.find_prompt()
            print resp

            # Entering config mode, deploying commands and exiting config mode
            resp = net_connect.send_config_set(CONF_COMMANDS)
            print resp

        except Exception as e:
            print e
            exit(0)
开发者ID:ahsec,项目名称:PyNet_Class_Exercises,代码行数:27,代码来源:exercise_07.py


示例12: main

def main():
    '''
    Use Netmiko to change the logging buffer size (logging buffered <size>)
    and to disable console logging (no logging console) from a file on
    both pynet-rtr1 and pynet-rtr2
    '''

    ip_address = raw_input("Please enter IP address: ")
    password = getpass()

    pynet_rtr1['ip'] = ip_address
    pynet_rtr2['ip'] = ip_address
    pynet_rtr1['password'] = password
    pynet_rtr2['password'] = password

    #for each router load config from
    #file and print result

    for router in (pynet_rtr1, pynet_rtr2):
        ssh_conn = ConnectHandler(verbose=False, **router)
        ssh_conn.send_config_from_file('ex8_config.txt')

        output = ssh_conn.send_command('show run | in logging')

        print "\n>>> {}:{}  \n".format(ssh_conn.ip, ssh_conn.port)
        print output
        print ">>>\n"
开发者ID:adleff,项目名称:python_ansible,代码行数:27,代码来源:ex8.py


示例13: main

def main():

    try:
        hostname = raw_input("Enter remote host to test: ")
    except NameError:
        hostname = input("Enter remote host to test: ")

    home_dir = path.expanduser("~")
    key_file = "{}/.ssh/cisco_rsa".format(home_dir)

    cisco_test = {
        "ip": hostname,
        "username": "testuser2",
        "device_type": "cisco_ios",
        "use_keys": True,
        "key_file": key_file,
        "verbose": False,
    }

    net_connect = ConnectHandler(**cisco_test)
    print()
    print("Checking prompt: ")
    print(net_connect.find_prompt())
    print()
    print("Testing show ip int brief: ")
    output = net_connect.send_command("show ip int brief")
    print(output)
    print()
开发者ID:Rosiak,项目名称:netmiko,代码行数:28,代码来源:test_cisco_w_key.py


示例14: main

def main():
    device_list = [cisco_ios, cisco_xr, arista_veos]
    start_time = datetime.now()
    print

    for a_device in device_list:
        as_number = a_device.pop('as_number')
        net_connect = ConnectHandler(**a_device)
        net_connect.enable()
        print "{}: {}".format(net_connect.device_type, net_connect.find_prompt())
        if check_bgp(net_connect):
            print "BGP currently configured"
            remove_bgp_config(net_connect, as_number=as_number)
        else:
            print "No BGP"

        # Check BGP is now gone
        if check_bgp(net_connect):
            raise ValueError("BGP configuration still detected")

        # Construct file_name based on device_type
        device_type = net_connect.device_type
        file_name = 'bgp_' + device_type.split("_ssh")[0] + '.txt'

        # Configure BGP
        output = configure_bgp(net_connect, file_name)
        print output
        print

    print "Time elapsed: {}\n".format(datetime.now() - start_time)
开发者ID:GnetworkGnome,项目名称:pynet,代码行数:30,代码来源:load_bgp_config_part4.py


示例15: main

def main():
    '''
    Use Netmiko to connect to each of the devices in the database. Execute
    'show version' on each device. Calculate the amount of time required to
    do this.
    '''
    django.setup()
    devices = NetworkDevice.objects.all()
    start_time = datetime.now()

    for a_device in devices:
        creds = a_device.credentials
        remote_conn = ConnectHandler(device_type=a_device.device_type,
                                     ip=a_device.ip_address,
                                     username=creds.username,
                                     password=creds.password,
                                     port=a_device.port, secret='')
        print
        print a_device
        print '#' * 80
        print remote_conn.send_command_expect("show version")
        print '#' * 80
        print

    elapsed_time = datetime.now() - start_time
    print "Elapsed time: {}".format(elapsed_time)
开发者ID:ibyt32,项目名称:pynet_test,代码行数:26,代码来源:w8e5_netmiko.py


示例16: main

def main():
    '''
    Use Netmiko to change the logging buffer size on pynet-rtr2.
    '''

    ip_addr = raw_input("Enter IP address: ")
    password = getpass()

    # Get connection parameters setup correctly
    for a_dict in (pynet1, pynet2, juniper_srx):
        a_dict['ip'] = ip_addr
        a_dict['password'] = password
        a_dict['verbose'] = False

    net_connect = ConnectHandler(**pynet2)

    config_commands = ['logging buffered 20000']
    net_connect.send_config_set(config_commands)

    output = net_connect.send_command("show run | i logging buffer")
    
    print
    print "Device: {}:{}".format(net_connect.ip, net_connect.port)
    print
    print output
    print
开发者ID:mstrocc,项目名称:PyNet-Python-Ansible,代码行数:26,代码来源:class4ex7_netmiko3.py


示例17: main

def main():
    username = 'pyclass'
    password = '88newclass'
    pynet1 = {
        'device_type': 'cisco_ios',
        'ip': '50.76.53.27',
        'username': username,
        'password': password,
        'port': 22,
    }
    pynet2 = {
        'device_type': 'cisco_ios',
        'ip': '50.76.53.27',
        'username': username,
        'password': password,
        'port': 8022,
    }
    juniper_srx = {
        'device_type': 'juniper',
        'ip': '50.76.53.27',
        'username': username,
        'password': password,
        'secret': '',
        'port': 9822,
    }


    pynet_rtr2 = ConnectHandler( **pynet2 )

    pynet_rtr2.config_mode()

    if pynet_rtr2.check_config_mode() :
        print "We are in config mode for pynet rtr2"
    else:
        print "No config mode for pynet rtr2"
开发者ID:kadamski-york,项目名称:pynet_testz,代码行数:35,代码来源:c4e5.py


示例18: main

def main():
    """Exercises using Netmiko"""
    # 99saturday
    sw1_pass = getpass("Enter switch password: ")

    pynet_sw1 = {
        'device_type': 'arista_eos',
        'ip':   '184.105.247.72',
        'username': 'admin1',
        'password': sw1_pass,
    }

    cfg_commands = [
        'vlan 901',
        'name red',
    ]

    net_connect = ConnectHandler(**pynet_sw1)
    print "Current Prompt: " + net_connect.find_prompt()

    print "\nConfiguring VLAN"
    print "#" * 80
    output = net_connect.send_config_set(cfg_commands)
    print output
    print "#" * 80
    print

    print "\nConfiguring VLAN from file"
    print "#" * 80
    output = net_connect.send_config_from_file("vlan_cfg.txt")
    print output
    print "#" * 80
    print
开发者ID:squeezer,项目名称:pynet_test,代码行数:33,代码来源:my_test26.py


示例19: main

def main():
    rtr1_pass = getpass("Enter router password: ")
    sw1_pass  = getpass("Enter switch password: ")

    pynet_rtr1 = {
        'device_type': 'cisco_ios',
        'ip':          '184.105.247.70',
        'username':    'pyclass',
        'password':    rtr1_pass,
    }

    pynet_sw1 = {
        'device_type': 'arista_eos',
        'ip':          '184.105.247.72',
        'username':    'admin1',
        'password':    sw1_pass,
    }

    for curr_device in (pynet_rtr1, pynet_sw1):
        sw_con = ConnectHandler(**curr_device)

        show_ver = sw_con.send_command("show version")
        show_run = sw_con.send_command("show run")

        save_file(sw_con.base_prompt + '-ver', show_ver)
        save_file(sw_con.base_prompt + '-run', show_run)
开发者ID:duncanbarter,项目名称:pynet_test,代码行数:26,代码来源:e03-25.py


示例20: show_version

def show_version(a_device):
    '''Establish connection with Netmiko + 'show version' command.'''
    creds = a_device.credentials
    remote_conn = ConnectHandler(device_type=a_device.device_type, port=a_device.port, ip=a_device.ip_address, username=creds.username, password=creds.password, secret='')
    print 'Establishing connection via Netmiko to all net devices ', '\n', remote_conn
    print 80 * '_'
    command_outp =  remote_conn.send_command_expect('show version')
开发者ID:wantonik,项目名称:pynet_wantonik,代码行数:7,代码来源:e6v3.py



注:本文中的netmiko.ConnectHandler类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python netmiko.Netmiko类代码示例发布时间:2022-05-27
下一篇:
Python regex.match函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap