0

I found this question and tried the solution given (accepted)

Can nmap take a list of ports to scan from a file?

However, it didn't really work as expected.

$ cat ports.list
21
22
23
25
$ 

Instead of scanning the ports in the file, nmap assume those ports as part of the host. See output below.

$ nmap 127.0.0.1 -vvv -p `cat ports.list`
Starting Nmap
Initiating Ping Scan at 10:50
Scanning 4 hosts [2 ports/host]
Completed Ping Scan at 10:50, 1.22s elapsed (4 total hosts)
Nmap scan report for 22 (0.0.0.22) [host down, received no-response]
Nmap scan report for 23 (0.0.0.23) [host down, received no-response]
Nmap scan report for 25 (0.0.0.25) [host down, received no-response]
Initiating Connect Scan at 10:50
Scanning localhost (127.0.0.1) [1 port]
Completed Connect Scan at 10:50, 0.00s elapsed (1 total ports)
Nmap scan report for localhost (127.0.0.1)
Host is up, received conn-refused (0.000059s latency).
Scanned for 1s

PORT   STATE  SERVICE REASON
21/tcp closed ftp     conn-refused

Read data files from: /usr/bin/../share/nmap
Nmap done: 4 IP addresses (1 host up) scanned in 1.28 seconds

$

Is it possible to take a list of ports to scan from a file?

1

Try a single line port specification without spaces, like such:

$ cat ports.list
21-23,25
$ 

That works as expected:

$ nmap -p `cat ports.list` host.example.com

Starting Nmap 7.60 ( https://nmap.org ) at 2021-03-25 15:07 UTC
Nmap scan report for host.example.com (192.168.1.17)
Host is up (0.00089s latency).

PORT   STATE  SERVICE
21/tcp closed ftp
22/tcp open   ssh
23/tcp closed telnet
25/tcp open   smtp

Nmap done: 1 IP address (1 host up) scanned in 0.05 seconds
$

Note that in the answer you reference, he used 'tr' to translate one-port-per-line into single-line-comma-delimited.

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.