Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import subprocess
- import sys
- import time
- import os
- import multiprocessing as mp
- from pexpect import pxssh
- import pexpect
- import getpass
- import re
- from joblib import Parallel, delayed
- from multiprocessing import Pool
- model= "def"
- def fttblogin(s): #login to fttb/jump function
- username = "a.kulyashov"
- #fttb = "jump1-int.vt.ru"
- fttb = 'fttb.mts-nn.ru'
- password = "*****"
- s.login (fttb, username, password)
- def nslogin(s): #login to newstat function
- username = "a.kulyashov"
- ns = "newstat.mts-nn.ru"
- #fttb = 'fttb.mts-nn.ru'
- password = "*****"
- s.login (ns, username, password,port=1122)
- def com_input(s):
- global model
- if model == 'huawei':
- s.sendline('system-view')
- s.sendline("snmp-agent sys-info contact NOC_test <noc@nnov.vt.ru>")
- s.sendline("q")
- s.sendline("q")
- def comstelnet(s,host):
- global model
- username = "a.kulyashov"
- compass = "*****"
- #compass = '*****'
- s.sendline ('telnet '+host)
- index = s.expect(['login:', 'Login authentication','WARNING - MONITORED', 'Login:', 'User Access Verification', 'User Name:', pexpect.EOF, pexpect.TIMEOUT])
- if index == 0:
- model = 'qtech'
- print str(host),'= Qtech'
- elif index == 1:
- model = 'huawei'
- print str(host),'= Huawei'
- elif index == 2:
- model = 'edgecore'
- print str(host),'= EdgeCore'
- elif index == 3:
- model = 'raisecom'
- print str(host),'= Raisecom'
- elif index == 4:
- model = 'cisco'
- print str(host),'= Cisco'
- elif index == 5:
- model = 'eltex'
- print str(host),'= Eltex'
- elif index == 6:
- print 'net priglasheniya'
- print 'neponyatni vendor'
- exit()
- elif index == 7:
- print 'out of time'
- print 'host nedostupen'
- exit()
- time.sleep(1)
- s.sendline (username)
- time.sleep(0.5)
- s.sendline (compass)
- time.sleep(0.5)
- com_input(s)
- s = pxssh.pxssh()
- ipslist=[]
- fttblogin(s) #login to fttb
- time.sleep(0.3)
- output = open("out.txt","w+")
- ipsfile = open("hostconfips.txt","r")
- output.truncate()
- for line in ipsfile:
- if line!='\n':
- ipslist.append(str(line).rstrip('\n').rstrip('\r'))
- start_time = time.time()
- num_cores = mp.cpu_count()
- results = Parallel(n_jobs=num_cores)(delayed(comstelnet)(s,host) for host in ipslist)
- elapsed_time = time.time() - start_time
- print ('time= '+str(elapsed_time))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement