Port scanning

The port scanning part refers to how we are going to implement it in our Python code. The idea is to use a combination of threading and multiprocessing. If we want 10 hosts to be scanned, we will break it into 5 batches. Each batch has two hosts (the batch size can be increased depending upon the RAM and processor capabilities of your lab machine). For a four-core processor and 2 GB RAM, the batch size should be 2. At any one time, we will process one batch and dedicate a single thread to each host. For this reason, two threads will be running in parallel to scan two hosts. Once a host is dedicated to a thread, the thread will pick the port range for that host to be scanned (let's say it's between 1 and 65535). Instead of scanning the ports sequentially, the logic is to break the whole range into three chunks, each of a size of 21,845. Now, the three chunks of a single host are scanned in parallel. If the number of processor cores is higher, the chunk size can be increased. For a four-core processor and 2 GB RAM, three chunks are recommended:

To summarize, hosts are broken into batches with a batch size of 2 and are dedicated to a single host. Further ports are broken into chunks and a multiprocessing process is dedicated to scan each chunk such that port scanning happens in parallel. Thus, at any one time, two threads and six processes will be running for a port scanning activity. If the user wants to pause the scan, they can use Ctrl + at the Terminal window to pause. When they rerun the code, they will be prompted with the option of launching a new scan or resuming an earlier paused scan.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.198.49