How to use the netmiko.Netmiko function in netmiko

To help you get started, we’ve selected a few netmiko examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ktbyers / netmiko / examples / use_cases / case7_commit / config_change_jnpr.py View on Github external
#!/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()
github ktbyers / pynet / presentations / dfwcug / examples / case10_ssh_proxy / conn_ssh_proxy.py View on Github external
#!/usr/bin/env python
from netmiko import Netmiko
from getpass import getpass

key_file = "/home/gituser/.ssh/test_rsa"

cisco1 = {
    'device_type': 'cisco_ios',
    'host': 'cisco1.twb-tech.com', 
    'username': 'testuser',
    'use_keys': True,
    'key_file': key_file,
    'ssh_config_file': './ssh_config',
}

net_connect = Netmiko(**cisco1)
print(net_connect.find_prompt())
output = net_connect.send_command("show ip arp")
print(output)
github ktbyers / netmiko / examples / troubleshooting / enable_logging.py View on Github external
from netmiko import Netmiko
from getpass import getpass

# This will create a file named 'test.log' in your current directory.
# It will log all reads and writes on the SSH channel.
logging.basicConfig(filename="test.log", level=logging.DEBUG)
logger = logging.getLogger("netmiko")

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()
github ktbyers / netmiko / examples / configuration_changes / config_changes.py View on Github external
#!/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()
github ktbyers / netmiko / examples / use_cases / case5_prompting / send_command_prompting.py View on Github external
#!/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 = "del flash:/test1.txt"
print()
print(net_connect.find_prompt())
output = net_connect.send_command_timing(command)
if "confirm" in output:
    output += net_connect.send_command_timing(
        "y", strip_prompt=False, strip_command=False
    )
net_connect.disconnect()
print(output)
print()
github ktbyers / pynet / learning_python / lesson6 / exercise5.py View on Github external
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()
github ktbyers / netmiko / examples / adding_delay / add_delay.py View on Github external
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",
    # Increase (essentially) all sleeps by a factor of 2
    "global_delay_factor": 2,
}

net_connect = Netmiko(**my_device)
# Increase the sleeps for just send_command by a factor of 2
output = net_connect.send_command("show ip int brief", delay_factor=2)
print(output)
net_connect.disconnect()
github ktbyers / pynet / presentations / dfwcug / examples / case8_autodetect / autodetect_ssh.py View on Github external
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())
github ktbyers / netmiko / examples / use_cases / case4_show_commands / send_command_expect.py View on Github external
#!/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, expect_string=r"#")
net_connect.disconnect()
print(output)
print()
github ktbyers / pynet / presentations / dfwcug / examples / case4_show_commands / send_command_expect.py View on Github external
#!/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, expect_string=r'#')
net_connect.disconnect()
print(output)
print()