Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output IP only from an nmap scan on open port

Tags:

shell

nmap

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

like image 371
user2341069 Avatar asked Aug 08 '13 15:08

user2341069


People also ask

How do I scan a nmap port?

How To Scan Nmap Ports. To scan Nmap Ports on a remote system, enter the following: sudo nmap 192.168.0.1. Replace the IP address with the IP address of the system you’re testing. This is the basic format for Nmap, and it will return information about the ports on that system.

How long does Nmap take to scan a host?

PORT STATE SERVICE 22/tcp open ssh 80/tcp open http Nmap done: 254 IP addresses (7 hosts up) scanned in 3.78 seconds as the above host is the only one with ALL the ports open. I certainly can post-process the output, but I don't want to rely on the output format of nmap, I'd rather have nmap do it, if there is a way. Show activity on this post.

How do I use the Nmap command?

Nmap commands can be used to scan a single port or a series of ports: Scan port 80 on the target system: Scan ports 1 through 200 on the target system: Scan (Fast) the most common ports:

How to scan open ports in Linux?

In order to scan various open ports on our system, we’ll use the command nmap. Before scanning any open ports we need to have nmap installed on our Linux system. Use one of the following options to install nmap on your system first:


1 Answers

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
like image 180
Elisiano Petrini Avatar answered Sep 22 '22 05:09

Elisiano Petrini