Skip to content

Instantly share code, notes, and snippets.

View ddutt's full-sized avatar

Dinesh Dutt ddutt

View GitHub Profile
def ssh2_ssh(host, port=22, user='vagrant', password='vagrant'):
# Make socket, connect
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, port))
# Initialise
session = Session()
session.handshake(sock)
session.userauth_password(user, password)
async def scrapli_ssh(host, port=22, user='vagrant', password='vagrant'):
dev_connect = {
"host": host,
"auth_username": user,
"auth_password": password,
"port": port,
"auth_strict_key": False,
"transport": "asyncssh",
}
async def async_ssh(host, port=22, user='vagrant', password='vagrant'):
conn = await asyncssh.connect(host, port=port,
username=user, password=password,
client_keys=None, known_hosts=None)
output = await conn.run(command)
# print(f'{host}, {output.stdout.strip()}, {output.exit_status}')
conn.close()
def netmiko_ssh(host, port=22, user='vagrant', password='vagrant'):
asyncssh scrapli ssh2-python paramiko netmiko
NXOS, Single Host, 10 Repeats 5.3104 14.6214 7.677 11.58 27.1105
NXOS, 4 Hosts, 10 Repeats 9.2573 17.8802 32.265 39.1216 91.0283
NXOS, Single Host, 3 Repeats 3.1058 4.0649 3.9866 4.3019 9.1016
NXOS, 4 Hosts, 3 Repeats 4.1840 5.2396 17.8295 21.4979 35.8407
Cumulus, Single Host, 10 Repeats 1.9506 -1 2.4926 3.3294 19.7455
Cumulus, 10 hosts, 10 Repeats 11.315 -1 66.3003 90.0536 215.1264
Cumulus, Single Host, 3 Repeats 0.6976 -1 0.7593 0.9228 4.5987
Cumulus, 10 Hosts, 3 Repeats 4.8957 -1 31.3517 28.6099 64.0242
Junos, Single Host, 10 Repeats 1.6286 1.9315 1.5417 1.6812 12.913
asyncssh scrapli ssh2-python paramiko netmiko
Version Tested 2.4.0 2020.8.28 0.17.0 2.7.2 3.3.0
Python3 Support Yes Yes Yes Yes Yes
Async Support Yes Yes No No No
Network Config Support No Yes No Yes Yes
Linux Support Yes No Yes Yes Yes
Password Auth Yes Yes Yes Yes Yes
Private Key Yes Yes Yes Yes Yes
Private Key with Passphrase Yes Yes Yes Yes Yes
Jumphost support Yes Yes Yes Yes Yes
@ddutt
ddutt / ssh_timeit.py
Created September 8, 2020 04:49
Benchmarking various Python SSH libraries for communicating with network devices
#!/usr/bin/env python3
import sys
import socket
from timeit import Timer
import asyncssh
import asyncio
import paramiko
@ddutt
ddutt / create_box.sh
Created June 2, 2020 06:24
create_box.sh to be used with creating libvirt for Arista's VEOS
#!/usr/bin/env bash
#set -xu
error() {
local msg="${1}"
echo "==> ERROR: ${msg}"
exit 1
}
usage() {
@ddutt
ddutt / Vagrantfile for NXOS libvirt
Last active June 2, 2020 04:49
Default Vagrantfile to use in ~/vagrant.d/boxes/ for Cisco's NXOSv
Vagrant.configure("2") do |config|
# Use Vagrant's default insecure key
config.ssh.insert_key = false
# Modify default shell behavior
config.ssh.shell = "run bash"
# Set timeout to 6 mins
config.vm.boot_timeout = 360
# Disable default host <-> guest synced folder
config.vm.synced_folder ".", "/vagrant", disabled: true
# Set guest OS type to disable autodetection