Port scanning in ethical hacking is the process of sending network packets to a target host to discover which TCP and UDP ports are open, closed, or filtered. Every open port represents a running service, a web server on port 80, an SSH daemon on port 22, a database on port 3306. Each service is a potential entry point. Knowing which ports are open, what software answers on them, and which version that software runs is intelligence that directly informs every attack decision in the phases that follow.
Beginner analogy: Think of port scanning like walking down a street and knocking on every door of a building. Some doors open — those are open ports with services running behind them. Some doors are locked but clearly occupied — closed ports. Some doors have no response at all, as if the room is hidden behind a wall — filtered ports blocked by a firewall. Port scanning maps every door in the building before deciding which one to try entering.
Port scanning is performed during the scanning and enumeration phase of ethical hacking, directly after reconnaissance. It is an active technique because it sends packets to the target system, generating logs and potentially triggering intrusion detection alerts. Written authorization from the target organization is required before any port scanning begins in a professional engagement.
Types of port scans used in ethical hacking
Scan Type 01: TCP SYN Scan (Stealth scan)
The most common and default Nmap scan. Sends a SYN packet and waits for SYN-ACK without completing the handshake. Faster and less detectable than a full connect scan because no full connection is established.
nmap -sS target
Scan Type 02: TCP Connect Scan (Full handshake)
Completes the full three-way TCP handshake. More detectable than SYN scan, but works without root privileges. Used when raw packet access is unavailable or when scanning through certain proxy configurations.
nmap -sT target
Scan Type 03: UDP Scan (Connectionless)
Probes UDP ports for services like DNS (53), DHCP (67), and SNMP (161). Significantly slower than TCP scans because closed UDP ports send ICMP unreachable responses, while open ports often give no response.
nmap -sU target
Scan Type 04: Version Detection (Fingerprinting)
Probes open ports to detect exact service names and software versions. Version information is then cross-referenced against CVE databases to identify known vulnerabilities for the specific version.
version running. nmap -sV target
Scan Type 05: OS Detection (Fingerprinting)
Sends crafted packets and analyzes TCP/IP stack responses to identify the target operating system and version. Knowing the OS narrows exploitation paths and informs privilege.
escalation strategies. nmap -O target
Scan Type 06: Script Scan (NSE) (Automated checks)
Runs Nmap Scripting Engine scripts against discovered services to check for specific vulnerabilities, misconfigurations, and exposed information. Combines port discovery with lightweight vulnerability checking in one pass.
nmap -sC -sV target
Understanding port states
What each port state means for ethical hackers
| State | Attack Priority | Next Action | Stealth Level Needed |
| open | High | Full version & script scan | Low (already found) |
| closed | None | Use for idle scan zombies | N/A |
| filtered | Medium (evade first) | Fragment, decoy, proxy | High |
| unfiltered | Low | Run SYN scan to check | Medium |
| open|filtered | Immediate resolve | -sS -sV on that port | Medium |
| closed|filtered | Low | -sS to disambiguate | Low |
The most complete Nmap port scanning command for ethical hacking engagements combines multiple scan types in one pass. Running nmap -sS -sV -sC -O -p- target performs a SYN scan across all 65535 ports, detects service versions, runs default scripts, and identifies the operating system simultaneously. This single command produces a comprehensive picture of the entire attack surface.
Best port scanning tools
| Nmap Industry standard Free The most widely used port scanner in ethical hacking. Supports all major scan types, OS detection, version fingerprinting, and an extensive scripting engine for vulnerability checks. nmap.org | Masscan High-speed scanner Free The fastest port scanner available. Can scan the entire internet address space in under six minutes. Used for large-scope external assessments where speed is prioritized over detail. github.com/robertdavidgraham/masscan | RustScan Fast port finder Free Extremely fast port scanner written in Rust that identifies all open ports in seconds then passes results directly to Nmap for detailed service and version analysis. github.com/RustScan/RustScan |
| Zenmap GUI interface Free The official graphical interface for Nmap. Ideal for beginners learning port scanning because it visualizes scan results, suggests common commands, and displays network topology maps. nmap.org/zenmap | Shodan Passive scanning Free / Pro Provides passive port scan results for any internet-facing host without sending a single packet to the target. Invaluable for stealthy reconnaissance of external infrastructure. shodan.io | RustScan Fast port finder Free Extremely fast port scanner written in Rust that identifies all open ports in seconds, then passes results directly to Nmap for detailed service and version analysis. github.com/RustScan/RustScan |
Legal requirement. Port scanning in ethical hacking is an active technique that generates logs on the target system. Performing port scans against any system without explicit written authorization from the system owner is illegal under computer fraud laws in most jurisdictions including the Computer Fraud and Abuse Act in the United States and the Computer Misuse Act in the United Kingdom. Always scan within your authorized scope.
Defense tip. Organizations can detect unauthorized port scanning using intrusion detection systems such as Snort and Suricata. Configuring firewall rules to return filtered responses rather than closed responses for sensitive ports limits the intelligence available to an attacker running reconnaissance scans against your infrastructure.

