Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import datetime
- import openpyxl
- import pygubu
- from openpyxl.styles import Color, PatternFill, Font, Border
- from openpyxl.styles import colors
- from openpyxl.cell import Cell
- today=(datetime.datetime.now())
- wb = openpyxl.Workbook()
- ws = wb.active
- ws.title = 'servernames'
- redFill = PatternFill(start_color='FF5733',
- end_color='FF5733',
- fill_type='solid')
- greenFill = PatternFill(start_color='33FF57',
- end_color='33FF57',
- fill_type='solid')
- with open("file.txt", "r") as ins:
- array = []
- count = 1
- for servername in ins:
- array.append(servername)
- response = os.system("ping -n 1 "+ servername)
- if response == 0:
- ws['A'+ str(count)]=(servername)
- ws['B'+ str(count)]=("online")
- ws['B' + str(count)].fill = greenFill
- ws['C' + str(count)]=today.strftime("%H:%M:%S")
- ws['D'+ str(count)]=today.strftime("%m/%d/%Y")
- count+=1
- else:
- ws['A'+ str(count)]=(servername)
- ws['B'+ str(count)]=("offline")
- ws['B' + str(count)].fill = redFill
- ws['C' + str(count)]=today.strftime("%H:%M:%S")
- ws['D'+ str(count)]=today.strftime("%m/%d/%Y")
- count+=1
- ws.column_dimensions["A"].width = 25.0
- wb.save("results.xlsx")
Advertisement
Add Comment
Please, Sign In to add comment