infosec/Introduccion-hacking-hack4u/tema_2_Reconocimiento/portScan.sh

39 lines
549 B
Bash
Raw Normal View History

2024-02-04 15:03:46 +01:00
#!/bin/bash
function ctrl_c() {
echo -e "\n\n[!] Saliendo... \n"
tput cnorm; exit 1
}
# Ctrl+C
trap ctrl_c SIGINT
declare -a ports=($(seq 1 65535))
function checkPort() {
(exec 3<> /dev/tcp/$1/$2) 2>/dev/null
if [ $? -eq 0 ]; then
echo -e "[+] Host $1 - Puerto $2 (abierto)"
fi
exec 3>&-
exec 3<&-
}
tput civis # Ocultar cursor
if [ $1 ]; then
for port in "${ports[@]}"; do
checkPort $1 $port &
done
else
echo -e "\n[!] Uso: $0 <ip-address>\n"
fi
wait
tput cnorm # Mostrar cursor