import re

from tqdm import tqdm
import requests

pattern = 'You have reached this page on port <b>(\d+)</b>.<br/>'
expression = re.compile(pattern)

f = open("port.txt", "w")

# for port in tqdm(range(80, 99), ascii=True):
for port in tqdm(range(1, 65536), ascii=True):

    URL = 'http://portquiz.net:%d'%port

    try:
        response = requests.get(URL, timeout=1)
    except:
#         print(port, "error", file = f)
        continue

    # return response.status_code
    result = expression.search(response.text)
    print(port, response.status_code, result[1], file = f)
    print(port, response.status_code, result[1])

    # exit()