Skip to content

Instantly share code, notes, and snippets.

@markberly
Created December 4, 2015 21:13
Show Gist options
  • Save markberly/d507e2c47231757fff0f to your computer and use it in GitHub Desktop.
Save markberly/d507e2c47231757fff0f to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#
# Written by: Mark Berly
import argparse
import pprint
from jsonrpclib import Server
# connect to the switch either via http or https
def connect( sIpOrHostname, username, password, secure=True ):
return Server( "%s://%s:%s@%s/command-api"
% ( "http" if not secure else "https", password, username, sIpOrHostname ) )
# collect MAC address table
def getConfigInfo( switch, enablePass ):
rc = switch.runCmds( 1, [ { "cmd": "enable", "input": enablePass },
"configure",
"show running-config" ] )
return rc[2]
def main():
# Create the command line parser / arguments
parser = argparse.ArgumentParser(description='Get MAC table information')
parser.add_argument( 'sIpOrHostname', help='Switch IP address or Hostname' )
parser.add_argument( 'username', help='Username' )
parser.add_argument( 'password', help='Password' )
parser.add_argument( "--http", help="Use unsecure http connection (default is https)",
action="store_false", default=True )
parser.add_argument( "--enable-password", help="Enable-mode password",
default="" )
args = parser.parse_args()
# connect to switch
switch = connect ( args.sIpOrHostname, args.username, args.password, args.http )
pp = pprint.PrettyPrinter(indent=2)
runConfig = getConfigInfo( switch, "www" )
pp.pprint(runConfig)
if __name__ == '__main__':
main()
@markberly
Copy link
Author

VERY basic script to dump a 'show run' from a switch running Arista EOS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment