Skip to content

Instantly share code, notes, and snippets.

@zPrototype
Last active April 25, 2020 02:13
Show Gist options
  • Save zPrototype/8880f151d14a89bf5c17890f0cf4b6a9 to your computer and use it in GitHub Desktop.
Save zPrototype/8880f151d14a89bf5c17890f0cf4b6a9 to your computer and use it in GitHub Desktop.
Python script to get status codes
import requests
import time
import argparse
from concurrent.futures import ThreadPoolExecutor
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--file", action="store", help="Enter path to domainfile")
parser.add_argument("-t", "--threads", action="store", help="Enter the number of threads you want to use")
args = parser.parse_args()
inputFile = args.file
threads = args.threads
def check_domain(domain):
try:
responseCode = requests.get("https://" + domain.strip(), timeout=2).status_code
print("Status code for {} is: {}".format(domain.strip(), responseCode))
return True
except:
return False
with open(inputFile, "r") as domainFile:
domains = domainFile.readlines()
counterValid = 0
counterInvalid = 0
startTime = time.time()
print("\n***Not showing invalid URLs***\n")
checked_domains = []
with ThreadPoolExecutor(max_workers=threads) as executor:
for line in domains:
checked_domains.append(executor.submit(check_domain, line))
passed_domains = list(filter(lambda x: x.result() is True, checked_domains))
failed_domains = list(filter(lambda x: x.result() is False, checked_domains))
print("\nThere were {0} valid URLs and {1} invalid URLs!".format(len(passed_domains), len(failed_domains)))
endTime = time.time() - startTime
print("It took {} seconds".format(round(endTime, 2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment