Guest User

ping spreadsheet

a guest
Oct 3rd, 2016
904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. import os
  2. import datetime
  3. import openpyxl
  4. import pygubu
  5. from openpyxl.styles import Color, PatternFill, Font, Border
  6. from openpyxl.styles import colors
  7. from openpyxl.cell import Cell
  8.  
  9. today=(datetime.datetime.now())
  10.  
  11. wb = openpyxl.Workbook()
  12. ws = wb.active
  13. ws.title = 'servernames'
  14.  
  15. redFill = PatternFill(start_color='FF5733',
  16.                    end_color='FF5733',
  17.                    fill_type='solid')
  18.  
  19. greenFill = PatternFill(start_color='33FF57',
  20.                    end_color='33FF57',
  21.                    fill_type='solid')
  22.  
  23. with open("file.txt", "r") as ins:
  24.     array = []
  25.     count = 1
  26.     for servername in ins:
  27.         array.append(servername)
  28.         response = os.system("ping -n 1 "+ servername)
  29.         if response == 0:
  30.             ws['A'+ str(count)]=(servername)
  31.             ws['B'+ str(count)]=("online")
  32.             ws['B' + str(count)].fill = greenFill
  33.             ws['C' + str(count)]=today.strftime("%H:%M:%S")
  34.             ws['D'+ str(count)]=today.strftime("%m/%d/%Y")
  35.             count+=1
  36.         else:
  37.             ws['A'+ str(count)]=(servername)
  38.             ws['B'+ str(count)]=("offline")
  39.             ws['B' + str(count)].fill = redFill
  40.             ws['C' + str(count)]=today.strftime("%H:%M:%S")
  41.             ws['D'+ str(count)]=today.strftime("%m/%d/%Y")
  42.             count+=1
  43.  
  44. ws.column_dimensions["A"].width = 25.0
  45. wb.save("results.xlsx")
Advertisement
Add Comment
Please, Sign In to add comment