June 27, 2005


A script to do nmap scanning on multiple hosts for a certain port

Sample Usage of the script

[araheja@dweller ~]$ ./scan.sh
Usage: ./scan <file_with_hosts_list> <port_number>
[araheja@dweller ~]$
[araheja@dweller ~]$ ./scan.sh hosts 22
192.168.1.1 has port 22 closed
192.168.1.2 has port 22 closed
192.168.1.244 has port 22 open
192.168.1.3 has port 22 closed
[araheja@dweller ~]$

######################################################################
#!/bin/bash

if [ $# -ne 2 ]
then
        echo "Usage: ./scan <file_with_hosts_list> <port_number>"
        exit
fi

PORT=$2
FILE=`cat $1`
for HOST in $FILE
do
        nmap -p $PORT -sT $HOST | grep open >&2 /dev/null
        if [ $? -eq 0 ]
        then
                echo $HOST has port $PORT open
        else
                echo $HOST has port $PORT closed
        fi
done
######################################################################

HOME - PATCHES - WHITEPAPERS - SCRIPTS - NOTES - HUMOR