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:
#!/bin/sh
# 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"
else
echo "$1:$2 closed"
fi
}

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

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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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: