Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#!/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()
#!/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)
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()
#!/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()
#!/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()
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()
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()
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())
#!/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()
#!/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()