24 lines
466 B
Bash
Executable File
24 lines
466 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# Check if two arguments are provided
|
|
if [ "$#" -ne 2 ]; then
|
|
echo "Usage: $0 <hostname or ip> <port-range>"
|
|
exit 1
|
|
fi
|
|
|
|
hostname=$1
|
|
port_range=$2
|
|
|
|
# Split the port range into start and end
|
|
IFS='-' read -ra PORTS <<< "$port_range"
|
|
start_port=${PORTS[0]}
|
|
end_port=${PORTS[1]}
|
|
|
|
# Iterate over the port range
|
|
for ((port=start_port; port<=end_port; port++))
|
|
do
|
|
(echo > /dev/tcp/$hostname/$port) &>/dev/null && echo "Port $port open"
|
|
done
|
|
|
|
exit 0
|