Information Security Projects - Port Scanner

Tell us what’s happening:

Port 443 returning closed for tests test_port_scanner_ip and test_port_scanner_verbose_ip_hostname_returned_multiple_ports.

When looking at IP address 209.216.230.240 and 137.74.187.104 through ports 440 to 445 and 440 to 450 respectively, the port 443 doesn’t pass as open contrary to the tests.

Your code so far

try:
    host_data = socket.gethostbyname_ex(target)
except socket.gaierror:
    pattern = r'^\d{1,3}(\.\d{1,3}){3}$'
    if re.match(pattern, target):
        return 'Error: Invalid IP address'
    else:
        return 'Error: Invalid hostname'

for port in range(port_range[0], port_range[1] + 1):
    try:
        with socket.create_connection((target, port), timeout=0.1):
            open_ports.append(port)
    except (socket.timeout, ConnectionRefusedError, OSError) as e:
        pass

if verbose:
    descriptive_string = []

    if host_data[0] == host_data[2][0]:
        descriptive_string.append(f'Open ports for {host_data[0]}')
    else:
        descriptive_string.append(f'Open ports for {host_data[0]} ({host_data[2][0]})')

    descriptive_string.append('\nPORT     SERVICE')

    for port in open_ports:
        service = ports_and_services.get(port)
        descriptive_string.append(f'\n{port:<9}{service}')

    return ''.join(descriptive_string)

return(open_ports)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

Information Security Projects - Port Scanner