Reconnaissance and Enumeration

A Python enumeration script must request HTTPS when port 443 is open, request HTTP only when 443 is closed and port 80 is open, and do nothing otherwise. Which structure ensures at most one request is made?

Show the answer

Correct answerD. if https_open: ... elif http_open: ...

AWhy not this: Each separate if is evaluated independently, so both requests run when both ports are open.

BWhy not this: A while loop repeats while a condition holds, so it could keep sending requests instead of choosing one.

CWhy not this: An unconditional loop requests both ports regardless of their state; no decision is made.

DWhy this is right: The elif is evaluated only when the first test fails, so the branches cannot both run.

An if/elif chain makes the branches mutually exclusive: the elif test runs only if the first test was false, so at most one request occurs. Two separate if statements are tested independently, so both requests run when both ports are open.