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) ...

Get Mastering Python for Networking and Security now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.