DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Is Site Down Script
// Tests if site is down/server is offline by trying to connect in specified time
import socket
import urllib2
def timeout(site, timeout):
save = socket.getdefaulttimeout()
try:
response = urllib2.urlopen(site)
socket.setdefaulttimeout(save)
except urllib2.URLError, err:
socket.setdefaulttimeout(save)
if err.__class__.__name__ == "URLError":
if isinstance(err[0], socket.timeout):
return True
return False
if timeout("http://www.dummy-site.com/test_timeout.html", 10):
print "Timeout detected"





