Guest User

Untitled

a guest
Oct 16th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. poller = select.poll()
  2.  
  3. ms = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  4. ms.bind((conf['host'], int(conf['port'])))
  5. ms.listen(2)
  6. poller.register(ms, select.POLLIN)
  7.  
  8. while True:
  9.     try:
  10.         readSocks = poller.poll()
  11.     except select.error:
  12.         continue
  13.  
  14.     for fheve in readSocks:
  15.         fh = fheve[0]
  16.         if fh == ms.fileno():
  17.             (ns, addr) = ms.accept()
  18.             if addr[0] in conf['white']:
  19.                 dic = {}
  20.                 #dic["hostname"]    = getHostname()
  21.                 dic["ps"]   = getPS()
  22.                 #dic["who"] = getWho()
  23.                 dic["uplo"] = getUptime()
  24.                 dic["ram"]  = getRAM()
  25.                 #dic["ips"] = getIPs()
  26.                 dic["disk"] = getDisk()
  27.                 if conf['pretty'] == "Y":
  28.                     put(ns, json.dumps(dic, indent=4))
  29.                 else:
  30.                     put(ns, json.dumps(dic))
  31.             else:
  32.                 put(ns, json.dumps({'error': "Unauthorized"}))
  33.             try:
  34.                 ns.shutdown(socket.SHUT_RDWR)
  35.                 ns.close()
  36.             except socket.error: pass
Add Comment
Please, Sign In to add comment