Skip to content

Domain to code status

#!/usr/bin/python3
import requests
requests.packages.urllib3.disable_warnings()


def report(input_str):
    with open('output.txt', 'a') as f:
        print(input_str)
        f.write(input_str + '\n')


def get_status_code(target):
    try:
        page = requests.get(target, timeout=2, allow_redirects=True, verify=False)
        return page.status_code
    except Exception as e:
        return "error"


with open("input.txt") as file:
    lines = file.readlines()
    for target_line in lines:
        target = target_line.strip()

        status_domain_http = get_status_code("http://" + target)
        status_domain_https = get_status_code("https://" + target)

        report("Domain: {} http: {} https: {}".format(
            target,
            status_domain_http,
            status_domain_https
        ))

input.txt

example.com
example.pl