Output IP only from nmap scan on open port

I want to find computers with open ssh in my subnet, but it shows all the hosts that are in the results, not just those that have open ports, this is my command

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

thanks

+7
shell nmap
source share
1 answer

You can choose with awk for printing only in certain cases and not for everyone.

For example, the following corresponds to the last field, if it contains ssh (but you can also check for 22) then it prints IP.

 nmap -PN -p 22 --open -oG - 192.168.*.* | awk '$NF~/ssh/{print $2}' > sshopen.txt 
+10
source share

All Articles