0
0
Bash Scriptingscripting~30 mins

Port scanning basics in Bash Scripting - Mini Project: Build & Apply

Choose your learning style9 modes available
Port scanning basics
📖 Scenario: You are a network technician who needs to check which ports are open on a local server to ensure the services are running correctly.
🎯 Goal: Build a simple Bash script that scans a range of ports on a given IP address and reports which ports are open.
📋 What You'll Learn
Create a variable holding the target IP address
Create a variable holding the start and end port numbers
Use a loop to scan each port in the range
Check if the port is open using Bash built-in tools
Print the list of open ports
💡 Why This Matters
🌍 Real World
Network administrators often need to check which ports are open on servers to troubleshoot connectivity or security issues.
💼 Career
Basic port scanning skills help in network monitoring, security auditing, and system administration roles.
Progress0 / 4 steps
1
Set the target IP address
Create a variable called target_ip and set it to the string "127.0.0.1".
Bash Scripting
Need a hint?

Use variable_name="value" syntax to create a variable in Bash.

2
Set the port range to scan
Create two variables called start_port and end_port and set them to 75 and 85 respectively.
Bash Scripting
Need a hint?

Assign numbers to variables without quotes in Bash.

3
Scan ports in the range
Use a for loop with variable port to iterate from start_port to end_port. Inside the loop, use timeout 1 bash -c " to try connecting to $target_ip on $port with /dev/tcp. If the connection succeeds, add the port number to a variable called open_ports separated by spaces.
Bash Scripting
Need a hint?

Use seq to generate numbers and timeout 1 bash -c "echo > /dev/tcp/$target_ip/$port" to test ports.

4
Print the open ports
Print the text "Open ports:" followed by the value of the variable open_ports.
Bash Scripting
Need a hint?

Use printf or echo to display the open ports.