Python SSH script to log into Extreme switch, run command and save output
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎12-13-2017 10:09 PM
I have been trying to write a python script that logins to Extreme switch via SSH2, runs commands and shows output. I looked at Extreme's github page but can't seem to find it. Is there a example script that someone can share that login and runs commands. I also heard there is a better way to screen scrap Extreme.
Thanks
Damon
Thanks
Damon
8 REPLIES 8
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎02-06-2018 05:10 AM
I think using netmiko is easy for python SSH scripting.
Very simple example:
from netmiko import ConnectHandler extrm_X460 = { 'device_type': 'extreme', 'ip': '172.16.10.2', 'username': 'admin', 'password': 'verysecret', 'port' : 12322, # optional, defaults to 22 } net_connect = ConnectHandler(**extrm_X460) output = net_connect.send_command('show switch') print(output)
Very simple example:
from netmiko import ConnectHandler extrm_X460 = { 'device_type': 'extreme', 'ip': '172.16.10.2', 'username': 'admin', 'password': 'verysecret', 'port' : 12322, # optional, defaults to 22 } net_connect = ConnectHandler(**extrm_X460) output = net_connect.send_command('show switch') print(output)
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎01-17-2018 05:02 PM
or something like:
#with SSH login without password and authentication keys enabled
import subprocess
try:
out = subprocess.check_output(['printf "show config\n" | ssh -o ForwardX11=no -T admin@10.0.0.1'], shell=True)
except subprocess.CalledProcessError as e:
out = e.output
print out
exit(1)
print "Switch output: %s\n" % out
#with SSH login without password and authentication keys enabled
import subprocess
try:
out = subprocess.check_output(['printf "show config\n" | ssh -o ForwardX11=no -T admin@10.0.0.1'], shell=True)
except subprocess.CalledProcessError as e:
out = e.output
print out
exit(1)
print "Switch output: %s\n" % out
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎01-16-2018 01:21 PM
Also add a last line with:
main()But argparse needs to be imported from somewhere..
main()But argparse needs to be imported from somewhere..
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎12-18-2017 06:50 AM
Yes, the script I provided only connects to a switch and exits, to print something you need to add more.
Just before xos.exit() enter lines for commands like:
print xos.cmd("show vlan")
Just before xos.exit() enter lines for commands like:
print xos.cmd("show vlan")
