I’ve updated the pyMultiChange.py script. It now is fully functional, with the addition of enable mode functionality. With this script, you can take a list of routers and switches from a text file and execute a series of commands, from a text file, all from SSH. For example:

I’m going to continue working on building out the pyRouterLib module, as there is so much functionality that could be added to that. I’ll keep you updated on the progress. As always, updates will be posted to my github.

I’ve been working to migrate my python scripts, that access Cisco routers and switches to utilize SSH. I’m building out a ‘pyRouterLib’ class, that currently doesn’t have much functionality, but I’m going to be building it out a lot more in the coming months. I’m also working on my pyMultiChange script, so that it utilizes SSH as well. Currently, the work is going well, although, there is still more work to go.

Here is the pyRouterLib library:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

#!/usr/bin/env python

classpyRouterLib:

'''

Requirments:

*** Modules:

os, getpass, paramiko, logging

'''

def __init__(self,host):

self.host=host

''' Granular debugging that assists in trouble shooting issues '''

def debug(self):

import logging

logging.basicConfig(level=logging.DEBUG)

''' Define where to get user credentials '''

def get_creds(self):

from os.path import expanduser

import os.path

homeDir=expanduser("~")

credsFile=".tacacslogin"

credsFile=homeDir+"/"+credsFile

ifos.path.isfile(credsFile):

print"Using existing credentials file."

credsFileLocation=open(credsFile)

self.username=credsFileLocation.readline()

self.username=self.username.strip('\n')

self.password=credsFileLocation.readline()

self.password=self.password.strip('\n')

self.enable=credsFileLocation.readline()

self.enable=self.enable.strip('\n')

credsFileLocation.close()

else:

import getpass

print"You have not created a credentials file. Lets create one..."

self.username=raw_input("Username: ")

self.password=getpass.getpass("User Password: ")

self.enable=getpass.getpass("Enable Password: ")

authFile=open(credsFile,'w+')

authFile.write(self.username+"\n")

authFile.write(self.password+"\n")

authFile.write(self.enable+"\n")

authFile.close()

print"Your credentials file has been created and is located at: "

print credsFile+"\n"

username=self.username

password=self.password

enable=self.enable

returnusername,password,enable

Here is the pyMultiShow.py script, which utilizes the pyRouterLib to obtain user credentials:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

#!/usr/bin/env python

from pyRouterLib import *

import os,argparse,paramiko,time

''' Define hosts file, command file, verbose variables '''

hosts_file=''

cmd_file=''

verbose=False

def arguments():

''' Function to define the script command line arguments '''

globalhosts_file,cmd_file,verbose

parser=argparse.ArgumentParser(description='A Python implementation of MultiChange, which allows you to make mass changes to routers and switches via SSH.')