Output IP only from an nmap scan on open port
Asked Answered
I

1

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

Introduce answered 8/8, 2013 at 15:27 Comment(0)
S
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
Sorghum answered 8/8, 2013 at 15:33 Comment(3)
Works fine when I don't output it to a text file, but when I do nothing shows upIntroduce
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.Afterglow
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!Introduce

© 2022 - 2024 — McMap. All rights reserved.