Advertisement
l31ank

CountIntSW

May 20th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.43 KB | None | 0 0
  1. from telnetlib import Telnet
  2. from glob import glob
  3. from base64 import b64decode
  4. from time import sleep
  5.  
  6. def get_id():
  7.     f = open('identifier.base' , 'r')
  8.     keep = f.read()
  9.     return keep.split('\n')
  10.  
  11. def countint(interfaces):
  12.     utp = [0 , 0 , 0 , 0]
  13.     fiber = [0 , 0 , 0 , 0]
  14.     id_utp , id_fiber = get_id()
  15.     print interfaces
  16.     print id_utp
  17.     print id_fiber
  18.     # for port in interfaces:
  19.        
  20.            
  21.  
  22.  
  23.  
  24. def get_interface(text , hostlen=0):
  25.     far = hostlen+7
  26.     text = text[text.find('status')+8 : text.find('KickmeOff')-far]
  27.     lines = text.split('\n')
  28.     intf = [line.split() for line in lines if len(line.split()) > 1]
  29.     print intf
  30.     return intf
  31.  
  32.  
  33. def get_hostname(text):
  34.     text = text[text.find('KickmeOn')+10 : text.find('#show')]
  35.     print text
  36.     return text
  37.  
  38.  
  39. def callmebaby(ip, username, password):
  40.     try:
  41.         call = Telnet(ip , timeout=5)
  42.         call.read_until("sername: ")
  43.         call.write(username + '\n')
  44.         call.read_until("assword: ")
  45.         call.write(password + '\n')
  46.         sleep(1)
  47.         print '[+] Login Success.'
  48.         if(call.read_until('>',2).find('>') != -1):
  49.             call.write('aitadmin'+'\n')
  50.         # !===================================================
  51.         call.write('terminal length 0'+'\n')
  52.         call.write('!==== KickmeOn'+'\n')
  53.         call.write('show interface status'+'\n')
  54.         call.write('!==== KickmeOff'+'\n')
  55.         call.write('terminal length 24'+'\n')
  56.         call.write('exit'+'\n')
  57.         call.close
  58.         print '[+] Execute Command Success.'
  59.         plaintext = call.read_all()
  60.         hostname = get_hostname(plaintext)
  61.         lstint = get_interface(plaintext , hostlen=len(hostname))
  62.         countint(lstint[1:])
  63.         print '[+] Analyze Log Success.'
  64.     except IOError,ImportError:
  65.         print '[-] Can not Telnet.'
  66.    
  67.  
  68.  
  69. def get_ip():
  70.     filesName = glob('*.txt')
  71.     all_ip = []
  72.     for fil in filesName:
  73.         text = open(fil , 'r')
  74.         device_ip = text.read().split('\r\n')
  75.         if(len(device_ip) != 0):
  76.             all_ip.append(device_ip)
  77.         else:
  78.             all_ip.append('Null')
  79.     return all_ip
  80.  
  81. username = str(b64decode('c2FrcmFwZWU='))
  82. password = str(b64decode('c2FrcmFwZWU0MQ=='))
  83. if __name__ == '__main__':
  84.     for ipl in get_ip():
  85.         if(ipl is not 'Null'):
  86.             for ip in ipl:
  87.                 callmebaby(ip, username, password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement