#!/usr/bin/env python # # A website utility program to check whether a website is # widely available for webizen to view and browse. # # return code 200 means A-OK # anything else returned, check on the code online # # Slight Improvement: # Reading a list of URLs from a file ############################################################# author = "YXNjaGVuYmFjaEBnbWFpbC5jb20=" import requests import socket import os import sys def chkWebsitesNoCerts(websites): # Checking simple websites # no certs and no authentications for ws in websites: mess ="" try: r = requests.get(ws, allow_redirects=False,timeout=2.0) except requests.exceptions.Timeout: r.status_code = "408" except socket.error as err: if err.args[0] == 10061 or err.args[0] == 10060: r.status_code = "520" mess = "This server you are trying to access is enjoying cognac, \ please check back at a later time." except requests.exceptions.ConnectionError as err: r.status_code = "520" mess = "This server you are trying to access is enjoying cognac, \ please check back at a later time." print ws[7:] + "\t \t" + str(r.status_code) + "\t " + mess # NOT Fully decided what to do with this function def chkWebsitesCerts(websites): # Change 'verify' to False if your website does # not have a certification issued by a public authority # Checking websites with Certs for ws in websites: r = requests.get(ws, verify=True) print ws + "\t\t\t" + str(r.status_code) def main(): # Examples websites to check if they are up or not up web = [] file = 'websites.txt' fname = os.path.curdir + '/'+ file if os.path.isfile(fname): f = open(fname, 'r') for i in f: i = i.strip() web.append(i) chkWebsitesNoCerts(web) f.close() else: print "File not found." print "Please place a file in the same location." sys.exit() main()