Python – Check HTTPS Status Codes

# Author: Kerry Cordero
# Version: 1.0.0
# Description: This script searches a text file "dr-dns.txt" for FQDNs, checks the HTTPS status code, and if it's in the range of 200-399 (GOOD) and if it's in the range of 400-500 (BAD)

import os
import requests

file_path = os.path.join(os.path.dirname(__file__), "dr-dns.txt")

with open(file_path, "r") as file:
    for line in file:
        fqdn = line.strip()
            response = requests.get(f"https://{fqdn}")
            status_code = response.status_code
            label = "GOOD" if 200 <= status_code < 300 else "BAD"
            print(f"FQDN: {fqdn} | HTTPS Status Code: {status_code} | Label: {label}")
        except requests.exceptions.RequestException as e:
            print(f"FQDN: {fqdn} | Error: {str(e)}")