With this scripts i check if a host is response on a given port with the bash's built-in /dev/tcp.
I can use ip address or domains(hostnames).
Script 1
#!/bin/bash
HOST_NAME="127.1"
HOST_PORT="80"
if ( (exec 3<>/dev/tcp/${HOST_NAME}/${HOST_PORT}) 2> /dev/null); then
echo -e "PORT: ${HOST_PORT} | ON"
else
echo -e "PORT: ${HOST_PORT} | OFF"
fi
exit;
Script 2
#!/bin/bash
HOST_NAME="127.1"
for HOST_PORT in {1..1000}
do
if ( (exec 3<>/dev/tcp/${HOST_NAME}/${HOST_PORT}) 2> /dev/null); then
echo -e "PORT: ${HOST_PORT} | ON"
else
echo -e "PORT: ${HOST_PORT} | OFF"
fi
done
exit;
Script 3
#!/bin/bash
HOST_NAME="127.1"
declare -A PORT_ON
for HOST_PORT in {1..65535}
do
if ( (exec 3<>/dev/tcp/${HOST_NAME}/${HOST_PORT}) 2> /dev/null); then
PORT_ON[${HOST_PORT}]="ON"
fi
done
for i in ${!PORT_ON[*]}
do
echo -e "$i : ${PORT_ON[$i]}"
done
exit;
On some of our local and online domains Script 3 hangs on some ports and takes longer to jump to the next port scan, for example on ssh(because of firewalls or other services). How can i manage this that it continues straight away and is it possible to speed the script up, it takes a long time, when i scan all 65535 ports an.
My GNU/Linux Distro:
Distributor ID: Debian
Description: Debian GNU/Linux 10 (buster)
Release: 10
Codename: buster
4.19.0-16-amd64
My /etc/apt/sources.list
deb http://security.debian.org/debian-security buster/updates main contrib
deb-src http://security.debian.org/debian-security buster/updates main contrib
deb http://deb.debian.org/debian/ buster-updates main contrib
deb-src http://deb.debian.org/debian/ buster-updates main contrib
I can only install from this repos.
bash script, check port response with bash's built-in /dev/tcp, time delay | hangs | speed up
how can i speed up and terminate the time delay?