How to create Port Scanner using a simple Python script
Port scanning is the first step of active reconnaissance to get the overall posture of the IT system. It is similar to a situation where a thief wants to enter the house via windows. If some windows are open, that simply means the thief has some chance of entering the house. Here, windows are similar to ports, if open gives a chance to attacker to try other things to get a foothold on target. There are many tools available such as Nmap, Masscan, etc. to identify open ports. In this article, we will learn how to create a port scanner using a simple python script.
By using python-nmap
On way to use python-nmap module to scan ports of IT system. Nmap is an open-source tool used to identify the open ports and services of the target system. You can install by using the below script:
pip install python-nmap
After successful installation, using three simple three lines of code allows you to identify open ports. You will get an output in json format.
import nmap testscanner=nmap.PortScanner() testscanner.scan('192.168.112.2')
You can check command line script by using testscanner.command_line() command.
This quick tutorial provides an idea of python-nmap module to scan open ports of the target system. Also, this module helps you to customize scripts based on requirements.
Subscribe us to receive more such articles updates in your email.
If you have any questions, feel free to ask in the comments section below. Nothing gives me greater joy than helping my readers!
Disclaimer: This tutorial is for educational purpose only. Individual is solely responsible for any illegal act.