#!/bin/bash input file format is: hostname USAGE: ./scan_oem_ports_remote_hosts.sh hostfile if test 'X'"$1" = 'X'; then echo -n "ENter full path and name of file containing host names: ";read file else file="$1" fi grep -v "^#" $file|while read host do if test 'X'"$host" = 'X'; then echo "Malformed line in input file, skipping, should be name $host" else RESULTS=$(ssh -n -q $host "timeout 5 bash -c 'oemap01.mydomain.com:4903 NOT open"}' if test "$RESULTS" != "OPEN"; then /usr/bin/dig +short $host | awk -v ip=$host '{print ip," " $NF " -->oemap01.mydomain.com 4903 NOT open"}' fi fi done
Other Tools you can use for the same instead of /dev/tcp
nc -vz -w5 hostname port (TCP)
nc -vzu -w5 hostname port (UDP)
Reference: https://superuser.com/questions/621870/test-if-a-port-on-a-remote-system-is-reachable-without-telnet
https://arunbavera.wordpress.com/category/em13c/
Laisser un commentaire