Today I was presented with the need to find all the machines on a network that have port 22 open.
This can easily be achieved with nmap.
sudo nmap -sS -p22 192.168.1.0/24
However the only box I had was a 'linux router' with a minimalistic linux install and no access to install extra packages.
What I ended up using was a very simple shell script with nothing more than a for loop and netcat.
#!/bin/bash for h in {2..254}; do nc -z 192.168.111.$h 22; if [ $? -eq 0 ]; then echo -e "192.168.111.$h\n"; fi done
The -z flag to nc ( netcat ) tells it 'no io' then I just test for the exit code it gives.
Simple.