擅长:python、mysql、java
<p>我使用这个脚本使用PyEZ和JSON来使用多个IP地址。在</p>
<pre><code>from jnpr.junos import Device
from lxml import etree
import json
config_file = open('config.json')
config = json.load(config_file)
config_file.close()
for host in config['ip']:
dev = Device(host=host, user=config['username'],
password=config['password'], port=22)
dev.open()
data = dev.rpc.get_config(options={'format':'set'})
file_name = dev.facts['fqdn']
print(etree.tostring(data))
dev.close()
f = open(file_name + '.txt', 'w')
f.write(etree.tostring(data))
f.close()
</code></pre>
<p>JSON文件如下所示:</p>
^{pr2}$