Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import logging
- import ipaddress
- import subprocess
- import os
- class mainCode():
- #Logging Params
- logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', filename='output.log', level=logging.DEBUG)
- logging.debug('Logging started')
- #Define Variables
- loginUser = 'user'
- loginPassword = "'pw'"
- sendCommands = "'display ip int br; system-view; test'"
- sendCommand2 = "'system-view'"
- logging.info('Variables Declared..')
- def debug(self):
- print('Using Username: {0}'.format(self.loginUser))
- print('Using Password: {0}'.format(self.loginPassword))
- print('Sending Command: {0}'.format(self.sendCommands))
- print('arlogin', '-u', self.loginUser, '-p', self.loginPassword, '-c', self.sendCommands, self.currentDevice)
- #Hosts
- def hosts(self):
- with open ('device-list.txt') as deviceList:
- for i in deviceList:
- currentDevice = i.rstrip('\n')
- logging.info('Currently working on {0}'.format(currentDevice))
- logging.info('Checking if {0} is online..'.format(currentDevice))
- check = os.system('ping -c 1 {0}'.format(currentDevice))
- if check == 0:
- logging.info('{0} responded successfully!'.format(currentDevice))
- os.system("echo 'Device: {0} is online... proceeding to configure' >> logfile.txt".format(currentDevice))
- sendSubprocess = os.system('arlogin -u {0} -p {1} -c {2} {3}'.format(self.loginUser, self.loginPassword, self.sendCommands, currentDevice))
- else:
- logging.info('{0} has failed to respond! Marking as offline..'.format(currentDevice))
- os.system('echo {0} >> offlinedevice.txt'.format(currentDevice))
- os.system("echo 'Device: {0} is offline! Ending.' >> logfile.txt".format(currentDevice))
- pass
- code = mainCode()
- #code.debug()
- logging.info('Function Hosts started..')
- code.hosts()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement