Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. import subprocess
  2. import sys
  3. import time
  4. import os
  5. import multiprocessing as mp
  6. from pexpect import pxssh
  7. import pexpect
  8. import getpass
  9. import re
  10. from joblib import Parallel, delayed
  11. from multiprocessing import Pool
  12.  
  13. model= "def"
  14. def fttblogin(s): #login to fttb/jump function
  15. username = "a.kulyashov"
  16. #fttb = "jump1-int.vt.ru"
  17. fttb = 'fttb.mts-nn.ru'
  18. password = "*****"
  19. s.login (fttb, username, password)
  20.  
  21. def nslogin(s): #login to newstat function
  22. username = "a.kulyashov"
  23. ns = "newstat.mts-nn.ru"
  24. #fttb = 'fttb.mts-nn.ru'
  25. password = "*****"
  26. s.login (ns, username, password,port=1122)
  27.  
  28.  
  29. def com_input(s):
  30. global model
  31. if model == 'huawei':
  32. s.sendline('system-view')
  33. s.sendline("snmp-agent sys-info contact NOC_test <noc@nnov.vt.ru>")
  34. s.sendline("q")
  35. s.sendline("q")
  36.  
  37.  
  38. def comstelnet(s,host):
  39. global model
  40. username = "a.kulyashov"
  41. compass = "*****"
  42. #compass = '*****'
  43. s.sendline ('telnet '+host)
  44. index = s.expect(['login:', 'Login authentication','WARNING - MONITORED', 'Login:', 'User Access Verification', 'User Name:', pexpect.EOF, pexpect.TIMEOUT])
  45. if index == 0:
  46. model = 'qtech'
  47. print str(host),'= Qtech'
  48. elif index == 1:
  49. model = 'huawei'
  50. print str(host),'= Huawei'
  51. elif index == 2:
  52. model = 'edgecore'
  53. print str(host),'= EdgeCore'
  54. elif index == 3:
  55. model = 'raisecom'
  56. print str(host),'= Raisecom'
  57. elif index == 4:
  58. model = 'cisco'
  59. print str(host),'= Cisco'
  60. elif index == 5:
  61. model = 'eltex'
  62. print str(host),'= Eltex'
  63. elif index == 6:
  64. print 'net priglasheniya'
  65. print 'neponyatni vendor'
  66. exit()
  67. elif index == 7:
  68. print 'out of time'
  69. print 'host nedostupen'
  70. exit()
  71. time.sleep(1)
  72. s.sendline (username)
  73. time.sleep(0.5)
  74. s.sendline (compass)
  75. time.sleep(0.5)
  76. com_input(s)
  77.  
  78. s = pxssh.pxssh()
  79. ipslist=[]
  80. fttblogin(s) #login to fttb
  81. time.sleep(0.3)
  82. output = open("out.txt","w+")
  83. ipsfile = open("hostconfips.txt","r")
  84. output.truncate()
  85. for line in ipsfile:
  86. if line!='\n':
  87. ipslist.append(str(line).rstrip('\n').rstrip('\r'))
  88. start_time = time.time()
  89. num_cores = mp.cpu_count()
  90.  
  91. results = Parallel(n_jobs=num_cores)(delayed(comstelnet)(s,host) for host in ipslist)
  92.  
  93. elapsed_time = time.time() - start_time
  94. print ('time= '+str(elapsed_time))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement