1

I'm very new to Nmap. I'm using Nmap to find open ports of an IP by this command:

nmap -v -Pn -p 1-100 "$ip" -oG -

Here is the output:

Host: IP

Ports:
6/closed/tcp/unknown
19/closed/tcp/chargen
20/closed/tcp/ftp-data
21/open/tcp/ftp
22/closed/tcp/ssh
23/closed/tcp/telnet
25/open/tcp/smtp
32/closed/tcp/unknown
50/closed/tcp/re-mail-ck
53/closed/tcp/domain
56/closed/tcp/xns-auth
62/closed/tcp/acas
68/closed/tcp/dhcpc
72/closed/tcp/netrjs-2
76/closed/tcp/deos
80/open/tcp//http
100/closed/tcp//newacct

Ignored State: filtered (83)

As you see there are some closed ports in the result too. How can I change my command so that only open ports are displayed?

3

Nmap has the option --open, which will filter out all the other potential states. If you are scanning under Linux, you could also use grep to achieve a very similar result.

Here is what the man pages have to say about it:

--open (Show only open (or possibly open) ports)

Sometimes you only care about ports you can actually connect to (open ones), and don't want results cluttered with closed, filtered, and closed|filtered ports. Output customization is normally done after the scan using tools such as grep, awk, and Perl, but this feature was added due to overwhelming requests. Specify --open to only see hosts with at least one open, open|filtered, or unfiltered port, and only see ports in those states. These three states are treated just as they normally are, which means that open|filtered and unfiltered may be condensed into counts if there are an overwhelming number of them.

| improve this answer | |
  • How should I apply --open to my command? Like this: nmap -v -Pn -p 1-100 --open "$ip" -oG - ? – Pablo Mar 19 at 8:43
  • @Pablo - Have you tried it? What was the result? – Demento Mar 19 at 9:20
  • 1
    Yes, I tried it several times, it seems to work. I wanted to be sure that I'm using the correct command. – Pablo Mar 19 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.