当前位置: 首页>>代码示例>>Python>>正文


Python netmiko.Netmiko类代码示例

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


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

示例1: getpass

#!/usr/bin/env python
from netmiko import Netmiko
from getpass import getpass

nxos1 = {
    'host': 'nxos1.twb-tech.com', 
    'username': 'pyclass', 
    'password': getpass(), 
    'device_type': 'cisco_nxos',
}

cfg_file = 'config_changes.txt'
net_connect = Netmiko(**nxos1)

print()
print(net_connect.find_prompt())
output = net_connect.send_config_from_file(cfg_file)
print(output)
print()

net_connect.save_config()
net_connect.disconnect()
开发者ID:ilique,项目名称:netmiko,代码行数:22,代码来源:config_change_file.py

示例2: getpass

from getpass import getpass

my_device = {
    "host": "host.domain.com",
    "username": "pyclass",
    "password": getpass(),
    "device_type": "cisco_ios",
}

"""
Cisco IOS behavior on file delete:

pynet-rtr1# delete flash:/small_file_bim.txt
Delete flash:/test1.txt? [confirm]y
pynet-rtr1
"""

net_connect = Netmiko(**my_device)
filename = "text1234.txt"
cmd = "delete flash:{}".format(filename)

# send_command_timing as the router prompt is not returned
output = net_connect.send_command_timing(cmd, strip_command=False, strip_prompt=False)
if "confirm" in output:
    output += net_connect.send_command_timing(
        "\n", strip_command=False, strip_prompt=False
    )

net_connect.disconnect()
print(output)
开发者ID:ktbyers,项目名称:netmiko,代码行数:30,代码来源:handle_prompts.py

示例3: getpass

#!/usr/bin/env python
from __future__ import print_function, unicode_literals

# Netmiko is the same as ConnectHandler
from netmiko import Netmiko
from getpass import getpass

my_device = {
    'host': "host.domain.com",
    'username': 'pyclass',
    'password': getpass(),
    'device_type': 'cisco_ios',
}

net_connect = Netmiko(**my_device)
cfg_commands = ['logging buffered 10000', 'no logging console']

# send_config_set() will automatically enter/exit config mode
output = net_connect.send_config_set(cfg_commands)
print(output)

net_connect.disconnect()
开发者ID:ilique,项目名称:netmiko,代码行数:22,代码来源:config_changes.py

示例4: getpass

#!/usr/bin/env python
from netmiko import Netmiko
from getpass import getpass

cisco1 = {
    "host": "cisco1.twb-tech.com",
    "username": "pyclass",
    "password": getpass(),
    "device_type": "cisco_ios",
}

net_connect = Netmiko(**cisco1)
command = "show ip int brief"

print()
print(net_connect.find_prompt())
output = net_connect.send_command(command, use_textfsm=True)
net_connect.disconnect()
print(output)
print()
开发者ID:ktbyers,项目名称:netmiko,代码行数:20,代码来源:send_command_textfsm.py

示例5: send_command

"""
Optional, use send_command() in conjunction with ntc-templates to execute a show command. Have
TextFSM automatically convert this show command output to structured data.
"""
from __future__ import print_function, unicode_literals
from netmiko import Netmiko
from getpass import getpass
from pprint import pprint

try:
    host = raw_input("Enter host to connect to: ")
except NameError:
    host = input("Enter host to connect to: ")

password = getpass()
device = {
    'host': host,
    'username': 'pyclass',
    'password': password,
    'device_type': 'cisco_ios',
}

command = 'show ip int brief'
net_connect = Netmiko(**device)
output = net_connect.send_command(command, use_textfsm=True)
print()
print('-' * 80)
pprint(output)
print('-' * 80)
print()
开发者ID:McGuireChris,项目名称:pynet,代码行数:30,代码来源:exercise5.py

示例6: getpass

#!/usr/bin/env python
from netmiko import Netmiko
from getpass import getpass

password = getpass()

cisco1 = {
    'host': 'cisco1.twb-tech.com',
    'username': 'pyclass',
    'password': password,
    'device_type': 'cisco_ios',
    'secret': password,
}

net_connect = Netmiko(**cisco1)
print(net_connect.find_prompt())
net_connect.send_command_timing("disable")
print(net_connect.find_prompt())
net_connect.enable()
print(net_connect.find_prompt())

# Go into config mode
net_connect.config_mode()
print(net_connect.find_prompt())
net_connect.exit_config_mode()
print(net_connect.find_prompt())
net_connect.disconnect()
开发者ID:ilique,项目名称:netmiko,代码行数:27,代码来源:enable.py

示例7: getpass

# SNMPv3
from netmiko.snmp_autodetect import SNMPDetect
from netmiko import Netmiko
from getpass import getpass

device = {
    'host': 'cisco1.twb-tech.com', 
    'username': 'pyclass', 
    'password': getpass(), 
}

snmp_key = getpass("Enter SNMP community: ")
my_snmp = SNMPDetect("cisco1.twb-tech.com", snmp_version="v3", user='pysnmp',
                     auth_key=snmp_key, encrypt_key=snmp_key, auth_proto="sha",
                     encrypt_proto="aes128")
device_type = my_snmp.autodetect()
print(device_type)

device['device_type'] = device_type
net_connect = Netmiko(**device)
print(net_connect.find_prompt())
开发者ID:ilique,项目名称:netmiko,代码行数:21,代码来源:autodetect_snmp_v3.py

示例8: getpass

#!/usr/bin/env python
from netmiko import SSHDetect, Netmiko
from getpass import getpass

device = {
    'device_type': 'autodetect',
    'host': 'cisco1.twb-tech.com', 
    'username': 'pyclass', 
    'password': getpass(), 
}

guesser = SSHDetect(**device)
best_match = guesser.autodetect()
print(best_match)                   # Name of the best device_type to use further
print(guesser.potential_matches)    # Dictionary of the whole matching result

device['device_type'] = best_match
connection = Netmiko(**device)

print(connection.find_prompt())
开发者ID:ilique,项目名称:netmiko,代码行数:20,代码来源:autodetect_ssh.py

示例9: getpass

#!/usr/bin/env python
from __future__ import print_function, unicode_literals

# Netmiko is the same as ConnectHandler
from netmiko import Netmiko
from getpass import getpass

my_device = {
    'host': 'host.domain.com',
    'username': 'pyclass',
    'password': getpass(),
    'device_type': 'cisco_ios',
}

net_connect = Netmiko(**my_device)

output = net_connect.send_command("show ip int brief")
print(output)

net_connect.disconnect()
开发者ID:ilique,项目名称:netmiko,代码行数:20,代码来源:show_command.py

示例10: getpass

#!/usr/bin/env python
from __future__ import print_function, unicode_literals

# Netmiko is the same as ConnectHandler
from netmiko import Netmiko
from getpass import getpass

my_device = {
    'host': "host.domain.com",
    'username': 'pyclass',
    'password': getpass(),
    'device_type': 'cisco_ios',
}

net_connect = Netmiko(**my_device)

# Make configuration changes using an external file
output = net_connect.send_config_from_file("change_file.txt")
print(output)

net_connect.disconnect()
开发者ID:ilique,项目名称:netmiko,代码行数:21,代码来源:config_changes_from_file.py

示例11: getpass

#!/usr/bin/env python
from netmiko import Netmiko
from getpass import getpass

device = {
    'host': 'srx1.twb-tech.com', 
    'username': 'pyclass', 
    'password': getpass(), 
    'device_type': 'juniper_junos',
}

commands = [
    'set system syslog archive size 240k files 3 '
]

net_connect = Netmiko(**device)

print()
print(net_connect.find_prompt())
output = net_connect.send_config_set(commands, exit_config_mode=False)
output += net_connect.commit(and_quit=True)
print(output)
print()

net_connect.disconnect()
开发者ID:ilique,项目名称:netmiko,代码行数:25,代码来源:config_change_jnpr.py

示例12: raw_input

try:
    host = raw_input("Enter host to connect to: ")
except NameError:
    host = input("Enter host to connect to: ")

password = getpass()
device = {
    'host': host,
    'username': 'pyclass',
    'password': password,
    'device_type': 'cisco_ios',
}

filename = 'smallfile'
command = 'delete flash:{}'.format(filename)

net_connect = Netmiko(**device)
output = net_connect.send_command_timing(command, strip_prompt=False, strip_command=False)
if 'confirm' in output:
    # I don't confirm the file delete.
    output += net_connect.send_command_timing('n', strip_prompt=False, strip_command=False)
else:
    raise ValueError("Expected confirm message in output")

print()
print('-' * 80)
print(output)
print('-' * 80)
print()
开发者ID:McGuireChris,项目名称:pynet,代码行数:29,代码来源:exercise3.py

示例13: getpass

#!/usr/bin/env python
from netmiko import Netmiko
from getpass import getpass

R01 = {
    "host": "192.168.1.32",
    "username": "admin",
    "password": getpass(),
    "device_type": "cisco_ios",
}

cfg_file = "config_changes.txt"
net_connect = Netmiko(**R01)

# routing table before change #
command = "show ip route"
print('routes PRE changes')
print(net_connect.find_prompt())
pre_routes = net_connect.send_command(command) 
print(pre_routes)
print()

# make changes #
print()
print(net_connect.find_prompt())
output = net_connect.send_config_from_file(cfg_file)
print(output)
print()

# routing table after changes #
print('routes POST changes')
开发者ID:befthimi,项目名称:neteng,代码行数:31,代码来源:netmiko_changes_from_file.py

示例14: raw_input


try:
    host = raw_input("Enter host to connect to: ")
except NameError:
    host = input("Enter host to connect to: ")

password = getpass()
device = {
    'host': host,
    'username': 'pyclass',
    'password': password,
    'device_type': 'cisco_ios',
}

net_connect = Netmiko(**device)

# Use send_config_set() to make config change
config = ['logging console', 'logging buffer 15000']
output = net_connect.send_config_set(config)
output_printer(output)

# Use send_config_from_file() to make config change
output = net_connect.send_config_from_file('config.txt')
output_printer(output)


message = "Verifying config change\n"
output = net_connect.send_command("show run | inc logging")
if '8000' in output:
    message += "Logging buffer is size 8000"
开发者ID:McGuireChris,项目名称:pynet,代码行数:29,代码来源:exercise4.py

示例15: getpass

#!/usr/bin/env python
from netmiko import Netmiko
from getpass import getpass

cisco1 = {
    'host': 'cisco1.twb-tech.com', 
    'username': 'pyclass', 
    'password': getpass(), 
    'device_type': 'cisco_ios',
}

net_connect = Netmiko(**cisco1)
command = 'copy flash:c880data-universalk9-mz.154-2.T1.bin flash:test1.bin'

print()
print(net_connect.find_prompt())
output = net_connect.send_command(command, delay_factor=4)
print(output)
print()
开发者ID:ilique,项目名称:netmiko,代码行数:19,代码来源:send_command_delay.py


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