Reconnaissance and Enumeration
A tester needs Bash to run the same nmap command against every address listed in targets.txt, one at a time. Which construct does this?
Show the answer
Correct answerA. while read ip; do nmap -sV $ip; done < targets.txt
AWhy this is right: The loop repeats its body for every line of the file, so each address is scanned in turn.
BWhy not this: The && operator combines two tests and runs the command at most once; it never repeats.
CWhy not this: Arithmetic increments a number once and runs nmap once; it does not read the file.
DWhy not this: An if statement checks a condition once; it does not iterate over the file's lines.
A while read loop repeats its body once for each line in the file, putting each address into the variable. The if test and the && chain evaluate a condition once and run the command at most once, so they do not repeat.