Why is only the port version not printed in the output?

42 views Asked by At

I was trying to automate the NMAP Port Scanning using Python. When I executed the script, all went good, excepting the version of the port.

Here's the code:

import nmap

nm = nmap.PortScanner()
targetip = 127.0.0.1
firstport = 1
lastport = 1000

for i in range(firstport, lastport + 1):
    portinfos = nm.scan(targetip, str(i), arguments='-sV')
    state = portinfos['scan'][targetip]['tcp'][i]['state']
    service = portinfos['scan'][targetip]['tcp'][i]['name']
    version = portinfos['scan'][targetip]['tcp'][i]['version']
    if state == 'open':
        print(f'\nPort: {i} \nService: {service} \nVersion: {version} \nStatus: {state}\n')

Output:

Port: 80
Service: http
Version:
Status: open

======================================================================

As you can see, all the informations were printed in the output, excepting the Version of the port (e.g. ProFTPd).

When I try to execute the NMAP command line manually, it works.

I've found no info about this issue online, neither on forums nor on the library's documation page.

Does someone know what I did wrong and how to fix it?

Useful info: VSCode 1.87.2; Python 3.9.0; python-nmap 0.7.1

0

There are 0 answers