Advertisement
Guest User

Untitled

a guest
May 26th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. from flask import Flask
  2. import wmi
  3.  
  4. app = Flask(__name__)
  5.  
  6. ip = ['server1', 'server2', 'server3', 'server4', 'server5']
  7. user = "username"
  8. password = "password"
  9. append_services = []
  10.  
  11. words = 'win32'
  12.  
  13.  
  14. @app.route("/")
  15. def service_status():
  16.     results = []  # Temp for result to return to html
  17.     for a in ip:
  18.         global append_services
  19.         print('\n'+a+'\n')
  20.         c = wmi.WMI(a, user=user, password=password)
  21.         get_names = c.Win32_Service()
  22.  
  23.         for y in get_names:
  24.             convert = str(y.Name)
  25.             append_services.append(convert)
  26.             append_services = \
  27.                 [w for w in append_services if w.startswith(words)]
  28.  
  29.         for l in append_services:
  30.             state_of_services = c.Win32_Service(Name=l)
  31.             if state_of_services:
  32.                 for x in state_of_services:
  33.                     convert1 = str(x.State)
  34.                     convert2 = str(x.Caption)
  35.                     results.append([a, [convert1, convert2]])  # Append results
  36.                     print(convert1 + "        " + convert2)
  37.  
  38.     # This part for generate HTML for return
  39.     html = ''
  40.     for i in results:
  41.         html += '<h2>Ip: ' + i[0] + '</br>'
  42.         html += '<h3>From ' + i[0][0] + ' to ' + i[0][1]
  43.  
  44.     return html
  45.  
  46. if __name__ == "__main__":
  47.     app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement