Booker

Saturday, December 24, 2016

Bash TCP open ports scanner

We can use the following code to scan a given target machine (or router)
echo "enter hostname or ip> ";
read myhost; for port in {7990..8003};
do
    (timeout 1 bash -c "echo >/dev/tcp/$myhost/$port" && echo "port $port is open" || echo "failed")
     2>&1 | grep -v "refused";
done

oneliners:
echo "enter hostname or ip> "; read myhost; for port in {7990..8003}; do (timeout 1 bash -c "echo >/dev/tcp/$myhost/$port" && echo "port $port is open" || echo "failed") 2>&1 | grep -v "refused"; done

without showing errors:
echo "enter hostname or ip> "; read myhost; for port in {7990..8003}; do (timeout 1 bash -c "echo >/dev/tcp/$myhost/$port" && echo "port $port is open") 2>&1 | grep -v "refused"; done

No comments:

Post a Comment