Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

Python 3 doesn't recognize the nmap module what am I fouling up here?

Cannot find reference 'PortScanner' in '__Init__.py'

This is my code:

import map

ns = nmap.PortScanner()

1 Answer

0 votes
by (26.4k points)

You've to install the nmap:

sudo apt-get install nmap

Now, install the python module

sudo pip3 install -U python-nmap

After this, try below code:

>>> import nmap

>>> nm = nmap.PortScanner()

>>> nm.scan('127.0.0.1', '22-443')

>>> nm.command_line()

'nmap -oX - -p 22-443 -sV 127.0.0.1'

>>> nm.scaninfo()

{'tcp': {'services': '22-443', 'method': 'connect'}}

>>> nm.all_hosts()

['127.0.0.1']

>>> nm['127.0.0.1'].hostname()

'localhost'

>>> nm['127.0.0.1'].state()

'up'

>>> nm['127.0.0.1'].all_protocols()

['tcp']

>>> nm['127.0.0.1']['tcp'].keys()

[80, 25, 443, 22, 111]

Wanna become a Python expert? Come and join the python certification course and get certified.

For more details, do check out the below video tutorial.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Oct 9, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Nov 27, 2020 in Python by bharathbk (280 points)
0 votes
1 answer
0 votes
1 answer
asked Jul 5, 2019 in Python by Sammy (47.6k points)

Browse Categories

...