Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import xml.etree.ElementTree
- import time
- from time import gmtime, strftime
- import subprocess
- import paramiko
- from scp import SCPClient
- vremya = strftime("%a, %d %b %Y %H:%M:%S")
- # Создание ssh клиента для подтягивания дампа через scp
- def createSSHClient(server, port, user, password):
- client = paramiko.SSHClient()
- client.load_system_host_keys()
- client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- client.connect(server, port, user, password)
- return client
- ssh = createSSHClient('192.168.2.117', 22, 'root', 'password')
- scp = SCPClient(ssh.get_transport())
- # Копируем
- scp.get(r'/home/vigruz/dump.xml', r'/etc/unbound/')
- class Profiler(object):
- def __enter__(self):
- self._startTime = time.time()
- def __exit__(self, type, value, traceback):
- print "Затрачено времени: {:.3f} sec".format(time.time() - self._startTime)
- with Profiler() as p:
- # Парсим только ip
- file = xml.etree.ElementTree.parse('/etc/unbound/dump.xml').getroot()
- ipconf = open('/etc/unbound/local.d/google.conf', 'w')
- massiv = []
- for result in file.iter('content'):
- if result.get('blockType') == 'ip':
- for addr in result.iter('ip'):
- zapis = addr.text
- massiv.append(zapis)
- massiv = list(set(massiv))
- for zapis in massiv:
- ipconf.write("private-address: " + zapis + "\n" )
- ipconf.close()
- logfile = open('/etc/unbound/ip.log', 'a')
- log = vremya + " В файл было записано " + str(len(massiv)) + " адресов."
- logfile.write( log + "\n" )
- logfile.close()
- # Рестарт unbound
- command = "/usr/local/sbin/unbound-control reload"
- r = subprocess.Popen(command, shell = True)
- r.wait()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement