Advertisement
Guest User

Untitled

a guest
Apr 15th, 2014
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. class Ping:
  2.  
  3.  
  4. def __init__(self):
  5. self.__lista_IP = ['host1','host2','host3']
  6. self.__Find_active_IP(self.__lista_IP)
  7.  
  8.  
  9. def __Find_active_IP(self, lista_IP):
  10.  
  11. try:
  12. logging.debug('def __Trova_nodi')
  13.  
  14. for IP in lista_IP:
  15. try:
  16. retcode = subprocess.call("ping " + IP, shell = True)
  17. if retcode != 0:
  18. lista_IP.remove(IP)
  19. print IP + ' FAIL: it doesn't reply'
  20. else:
  21. print IP + ' OK: it is active'
  22.  
  23. except OSError as e:
  24. print str(e)
  25.  
  26. print self.__lista_IP
  27.  
  28. except Exception as e:
  29. print str(e)
  30.  
  31.  
  32.  
  33. if __name__=='__main__':
  34. run = Ping()
  35.  
  36. 127.0.0.1 host1
  37. 127.0.0.1 host2
  38. 127.0.0.1 host3
  39.  
  40. ping: unknown host host1
  41. host1 FAIL: it doesn't reply
  42. ping: unknown host host3
  43. host3 FAIL: it doesn't reply
  44. ['host2']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement