Scan modes with python-nmap
In this section, we will review the scan modes supported in the python-nmap module. This module allows the automation of port scanner tasks and can perform scans in two ways—synchronously and asynchronously:
- With synchronous mode, every time scanning is done on one port, it has to finish to proceed to the next port.
- With asynchronous mode, we can perform scans on different ports simultaneously and we can define a callback function that will execute when a scan is finished on a specific port. Inside this function, we can perform additional operations such as checking the state of the port or launching an Nmap script for a specific service (HTTP, FTP, or MySQL).
Let's go over these modes one by one in more detail and try to implement them.
Implementing synchronous scanning
In the following example, we are implementing an NmapScanner
class that allows us to scan an IP address and a list of ports that are passed as a parameter...