Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ❤ 💻
We are community of people that helps each other.

If you are beginner in IT field, you are more then welcome to ask questions, it will help you to learn faster. We are here to help you.

We are always beginner in something, we just need to remember it along the way.

there are no wrong questions - Ask Question

Bash - how to scan open ports with netcat / nc in Debian Linux?

0 contributions
2 points

Using Bash it is possible to scan ports with netcat (nc command) in Debian family Linux in following way.

1. Netcat bash script example

port_scanner.sh script file:

#!/bin/bash

broken=0;

function break_script
{
	broken=1;
}

trap break_script SIGINT;

for (( i = 1; i < 65535; ++i ))
do
	nc -z -w 1 "$1" "$i" < /dev/null;

	[ $? -eq 0 ] && echo "Open port $i";
	[ $broken -eq 1 ] && break;
done

Running:

$ ./port_scanner.sh 127.0.0.1
Open port 22
Open port 80
Open port 111
Open port 3306
Open port 8005
Open port 8080

Note: if nc command does not exist use following commands:

$ sudo apt-get update
$ sudo apt-get install netcat
0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more