Guest User

Untitled

a guest
Jan 9th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. import urllib2
  2. import socket
  3. import logging
  4.  
  5.  
  6. def check_url( url, timeout=5 ):
  7.     try:
  8.         return urllib2.urlopen(url,timeout=timeout).getcode() == 200
  9.     except urllib2.URLError as e:
  10.         return False
  11.     except socket.timeout as e:
  12.         print False
  13. ############## Estas dos lineas no las uses
  14. print check_url("http://www.google.com")  # Envia True  por que existe
  15. print check_url("http://xasx.cl") #Envia False por que no esta DIsponible  
  16.  
  17. ########################En Desarrolloso-->>> first TEST
  18. #def check_url( url, timeout=5 ):
  19. #    try:
  20. #        return urllib2.urlopen(url,timeout=timeout).getcode() == 200
  21. #    except urllib2.URLError as e:
  22. #        return False
  23. #    except socket.timeout as e:
  24. #        print False         # ACTIVA ESTAS LINEAS DE AQUI PAR ABAJO ####
  25. #    checker = check_url("http://" + args.host)
  26. #    if(checker == True):
  27. #      logging.info("El Servidor esta: ONLINE")
  28. #    if not(checker == True):
  29. #      logging.info("El Servidor esta: OFFLINE")
  30. ###################################
Advertisement
Add Comment
Please, Sign In to add comment