
Untitled
By: a guest on
May 8th, 2012 | syntax:
Bash | size: 0.70 KB | hits: 24 | expires: Never
#!/bin/bash
UH=$1
shift
regex="\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"
tmp="$(echo $UH | cut -d@ -f2)"
ip="$(echo $tmp | cut -d: -f1)"
port="$(echo $tmp | cut -d: -f2)"
if [[ -z $(echo $ip | egrep $regex) ]];
then
ip="$(host $ip | head -1 | cut -d' ' -f4)"
fi
echo $ip;
for ARG in "$@"
do
{
echo "Testing $ip:$ARG"
if ! exec 3<> /dev/tcp/$ip/$ARG; then
echo 0
else
echo 1
fi
} 2> /dev/null | {
while true; do
read line || break
case $line in
0) echo " [CLOSED]" ;;
1) echo " [OPEN]" ;;
*) echo -n $line ;;
esac
done
}
done