Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Ping:
- def __init__(self):
- self.__lista_IP = ['host1','host2','host3']
- self.__Find_active_IP(self.__lista_IP)
- def __Find_active_IP(self, lista_IP):
- try:
- logging.debug('def __Trova_nodi')
- for IP in lista_IP:
- try:
- retcode = subprocess.call("ping " + IP, shell = True)
- if retcode != 0:
- lista_IP.remove(IP)
- print IP + ' FAIL: it doesn't reply'
- else:
- print IP + ' OK: it is active'
- except OSError as e:
- print str(e)
- print self.__lista_IP
- except Exception as e:
- print str(e)
- if __name__=='__main__':
- run = Ping()
- 127.0.0.1 host1
- 127.0.0.1 host2
- 127.0.0.1 host3
- ping: unknown host host1
- host1 FAIL: it doesn't reply
- ping: unknown host host3
- host3 FAIL: it doesn't reply
- ['host2']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement