Complete the code to scan port 80 on a target IP using netcat.
nc -zv [1] 80
The nc -zv command scans the specified port on the given host. Here, localhost refers to your own machine.
Complete the code to scan ports 20 to 25 on a target IP using a for loop.
for port in [1]; do nc -zv 127.0.0.1 $port; done
The brace expansion {20..25} generates the sequence of numbers from 20 to 25, which the loop iterates over.
Fix the error in the code to scan port 443 on a target IP stored in variable $target.
nc -zv [1] 443
Using ${target} ensures the variable is expanded correctly in bash.
Fill both blanks to create a loop that scans ports 80 to 82 on IP 10.0.0.1.
for port in [1]; do nc -zv [2] $port; done
The brace expansion {80..82} generates ports 80, 81, and 82. The IP 10.0.0.1 is the target to scan.
Fill all three blanks to create a dictionary-like output of ports and their status using a loop and conditional.
for port in [1]; do nc -z [2] [3] $port && echo "$port: open" || echo "$port: closed" done
The loop scans ports 22 to 24 on localhost (127.0.0.1) with verbose flag -v. The conditional prints if the port is open or closed.