#!/bin/bash while read host do #verify that the host is up #/usr/sbin/ping $host -n 1 > /dev/null 2>&1 ping -c 1 $host > /dev/null 2>&1 #if it is up, then extract the banners if [[ $? -ne 0 ]] then echo "HOST: $host INACCESSIBLE" else unset host_name host_name=$(nslookup $host | while read a b do if [[ "$a" == "Name:" ]] then echo $b fi done) if [[ -z "$host_name" ]] then host_name=$host fi ######get the telnet banner osbanner=$( ( echo set escape + echo open $host sleep 5 echo + echo quit ) | telnet 2>/dev/null | egrep -v '(^telnet|^Connected|^Escape|^Local|^login)' | tr -d '[:cntrl:]' ) echo -e "HOST: $host_name\t$osbanner" ######examine the SMTP banner port=25 #most likely sendmail unset banner25 exec 3<>/dev/tcp/$host/$port if [[ $? -ne 0 ]] then echo -e "\tSMTP: NULL" else while read a b c do case $a in 220*) #remove "^220 host" and ";date$" from sendmail banner25=${c%;*} if [[ -z "$banner25" && -n "$a" ]] #not sendmail then banner25="$a $b $c" fi echo quit >&3 break ;; esac done <&3 if [[ -n "$banner25" ]] then echo -e "\tSMTP: $banner25" fi fi ######examine the FTP banner port=21 unset banner21 exec 3<>/dev/tcp/$host/$port if [[ $? -ne 0 ]] then echo -e "\tFTP: NULL" else while read a b c do case $a in 220*) if [[ "$host" = "$b" || "$host_name" = "$b" || ${host_name%%.*} = "$b" ]] then #suppress redundant host display banner21=${c} else if [[ -n "$b" && -n "$c" ]] then banner21="${b} ${c}" fi fi echo quit >&3 break ;; esac done <&3 if [[ -n "$banner21" ]] then echo -e "\tFTP: $banner21" fi fi ######examine the SSH banner port=22 unset banner22 exec 3<>/dev/tcp/$host/$port if [[ $? -ne 0 ]] then echo -e "\tSSH: NULL" else read banner22 <&3 echo quit >&3 if [[ -n "$banner22" ]] then echo -e "\tSSH: $banner22" fi fi fi done