I.T. Security and Linux Administration

Dec 31 2012   2:45PM GMT

Shell Portscanner

Eric Hansen Eric Hansen Profile: Eric Hansen

Many, many people have heard of nmap before. The infamous port scanner that does everything you can think of. This is great if you’re wanting to do recon on a network, but what if you just want to see what ports are open on a network without all the extra special features? Easy, you use Bash!

Below is a simple Bash script that uses the system’s TCP “device” to establish the connection and see if the port is open or closed:
# Code is swipped from http://legroom.net/2010/05/02/port-testing-and-scanning-bash
# Usage: ./portscan.sh
# Change range in {...} block as you please.

function port() {
(echo > /dev/tcp/$1/$2) &> /dev/null
if [ $? -eq 0 ]; then
echo "$1:$2 open"
echo "$1:$2 closed"

for i in {22..80}; do
port $1 $i

This does a check for ports 22-80, but you can change the range to match your needs. A link to this can be found here: https://gist.github.com/4422216

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: