Port scan using bash

Checking the opened port for any remote IP on your network or others.

  1
  2 #!/bin/bash
  3
  4 # Test remote host:port availability (TCP-only as UDP does not reply)
  5     # $1 = hostname
  6     # $2 = port
  7 function port() {
  8     (echo >/dev/tcp/$1/$2) &>/dev/null
  9     if [ $? -eq 0 ]; then
 10         echo "$1:$2 is open"
 11     else
 12         echo "$1:$2 is closed"
 13     fi
 14 }
 15
 16
 17 #source=/home/nicolas/log_ssh/
 18 #today=$(date +"%b %e")
 19
 20 #cat "$source"ssh_failed_all_since_"$today".log | while read line;do
 21 #echo "..processing $line $i"
 22 echo "please wait..."
 23 for i in $(seq 1 1024); do
 24 echo "checking port $1.."
 25 port $1 $i; done | grep open

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *