import sys from jsonrpclib import Server from pprint import pprint as pp user = '******' passwd = 'P3pp3r101!' ip = '192.168.11.1' url = "http://%s:%s@%s/command-api" % (user, passwd, ip) switch = Server(url) result_mgmt_interface = switch.run_Cmds( 1, ['enable', { 'cmd': 'show ip interface' }])[1]['interfaces'] mgmt_vlan = 'Vlan1910' mgmt1 = 'Management1' def get_mgmt_ip(): if mgmt_vlan in result_mgmt_interface: mgmt_iface = switch.runCmds( 1, ["enable", { "cmd": "show interfaces Vlan1910" }])[1]['interfaces']['Vlan1910']['interfaceAddress'][0][ 'primaryIp']['address'] return mgmt_iface else: if mgmt1 in result_mgmt_interface: mgmt_iface = switch.runCmds( 1, ["enable", { "cmd": "show interfaces management 1"