O'Reilly logo

Mastering Python for Networking and Security by Jose Manuel Ortega

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using python-nmap

Now, you can import the python-nmap module that we can invoke from our scripts, or from the interactive terminal, for example:

Once we have verified the module installation, we can start to perform scans on a specific host. For this, we must do an instantiation of the PortScanner() class, so we can access the most important method: scan(). A good practice to understand how a function, method, or object works is to use the help() or dir() functions to find out the methods available in a module:

If we execute a help (port_scan.scan) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required