From 2654ebeec80c4ff4b83ceff3fe6aaf2937fb5081 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 20 Jan 2017 12:50:55 +0000 Subject: [PATCH] =?UTF-8?q?=D0=AD=D1=82=D0=BE=D1=82=20=D1=81=D0=BA=D1=80?= =?UTF-8?q?=D0=B8=D0=BF=D1=82=20=D0=BF=D1=8B=D1=82=D0=B0=D0=B5=D1=82=D1=81?= =?UTF-8?q?=D1=8F=20=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B8=D1=82=D1=8C?= =?UTF-8?q?=20dlink'=D0=B8=20=D0=BD=D0=B0=20snmp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- djing/utils/push_snmp_passw.py | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 djing/utils/push_snmp_passw.py diff --git a/djing/utils/push_snmp_passw.py b/djing/utils/push_snmp_passw.py new file mode 100644 index 0000000..e4d2dbc --- /dev/null +++ b/djing/utils/push_snmp_passw.py @@ -0,0 +1,45 @@ +# -*- coding: utf8 -*- +import telnetlib +from mydefs import ping +from socket import error +from multiprocessing import Process + + +# Пробуем настроить свичи через telnet на snmp + + +def cmd(ip): + tn = telnetlib.Telnet(ip) + tn.read_until("login: ") + tn.write("\n") + tn.read_until("Password: ") + tn.write("\n") + + tn.write("create snmp community ertNjuWr ReadWrite\n") + tn.write("save\n") + tn.write("save config\n") + tn.write("save config config_id 1\n") + + tn.write("log\n") + print(tn.read_all()) + tn.close() + + +def prc(ip): + try: + if ping(ip): + cmd(ip) + except error: + print('Error connect to', ip) + + +if __name__ == '__main__': + proc_list = list() + with open('swips.txt', 'r') as f: + for ln in f: + ip = ln.strip() + p = Process(target=prc, args=(ip,)) + p.start() + proc_list.append(p) + for proc in proc_list: + proc.join()