7

I'm wanting to find computers with ssh open on my subnet but it shows all host that are up in the results and not just the ones that have open ports this is my command

nmap -PN -p 22 --open -oG - 192.168.*.* | awk '{print $2}' > sshopen.txt

Thanks

user2341069
  • 389
  • 5
  • 8
  • 14

1 Answers1

10

You can select with awk to print only in certain cases and not all.

For example, the following matches the last field, if it contains ssh (but you could test also for 22) then it prints the IP.

nmap -PN -p 22 --open -oG - 192.168.*.* | awk '$NF~/ssh/{print $2}' > sshopen.txt
  • Works fine when I don't output it to a text file, but when I do nothing shows up – user2341069 Aug 08 '13 at 15:38
  • presumably because the command's output is going to the text file instead of the screen. instead of `> sshopen.txt`, use `| tee sshopen.txt` if you want the output to go to *both* the screen and the file. – Christopher Neylan Aug 08 '13 at 15:44
  • It just took a while to show up in the text file, might of been waiting for a scan percentage to be completed, thanks guys! – user2341069 Aug 08 '13 at 15:49