A Python enumeration script loops through a list of target IP addresses and calls socket.connect_ex() to test whether TCP port 22 is open. The integer variable open_port_count tracks how many targets have been confirmed with the port open. Which one-line statement should be executed immediately after a successful connection to ensure open_port_count is updated correctly while preserving its integer type?
The += augmented-assignment operator adds 1 to the existing integer in place, giving an accurate running total. Converting the counter to a string before concatenation (str(open_port_count) + "1") changes its data type to str, breaking later arithmetic. Decrementing (open_port_count -= 1) reduces the count instead of increasing it. A bitwise AND with 1 (open_port_count = open_port_count & 1) forces the value to 0 or 1, discarding counts above 1.
Python treats x += 1 as a shorthand for x = x + 1, evaluated once and kept as the same numeric type. See Python 3 documentation, section "Augmented assignment statements."
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the variable listeningPorts represent in this context?
Open an interactive chat with Bash
Why does listeningPorts = listeningPorts + 1 properly update the count?
Open an interactive chat with Bash
Why is multiplying by zero or assigning 1 + 0 incorrect?