Сам json возьмем
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 |
#! /usr/bin/python3 from paramiko import SSHClient from paramiko import AutoAddPolicy import json import requests from getpass import getpass ipssh = "" login = "admin" passw = "st" url = "http://api.voximplant.com/getMediaResources?with_webgateways&with_mediaservers&with_jsservers&with_sbcs" response = requests.get(url) data = response.json() #print (data) js_servers = data["js_servers"] media_servers = data["media_servers"] web_gateways = data["web_gateways"] ip = [] for i in range(0, len(js_servers)): ip.append(js_servers[i]["address"]) for i in range(0, len(media_servers)): ip.append(media_servers[i]["hostname"]) for i in range(0, len(web_gateways)): ip.append(web_gateways[i]["hostname"]) ssh = SSHClient() ssh.set_missing_host_key_policy(AutoAddPolicy()) ssh.connect(ipssh,port=22,username=login,password=passw) for i in range(0, len(ip)): cmd = "/ip firewall address-list add address="+ip[i]+ " list=bitix_voximplant_ip" ssh.exec_command(cmd) ssh.close() |