March 25, 2021

nmap to read ports from a file

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

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

$ nmap -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 ( [host down, received no-response]
Nmap scan report for 23 ( [host down, received no-response]
Nmap scan report for 25 ( [host down, received no-response]
Initiating Connect Scan at 10:50
Scanning localhost ( [1 port]
Completed Connect Scan at 10:50, 0.00s elapsed (1 total ports)
Nmap scan report for localhost (
Host is up, received conn-refused (0.000059s latency).
Scanned for 1s

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?



I am by no means an expert, but I’ve found that I had to specify the ports in the command, I’ve only ever used the -iL switch for a list of IP’s.

Leave a Reply

Your email address will not be published. Required fields are marked *

Note: By filling this form and submitting your commen, you acknowledge, agree and comply with our terms of service. In addition you acknowledge that you are willingly sharing your email address with AiOWikis and you might receive notification emails from AiOWikis for comment notifications. AiOWiksi guarantees that your email address WILL NOT be used for advertisement or email marketting purposes.

This site uses Akismet to reduce spam. Learn how your comment data is processed.