Blog

Port Scanner: How Port Scanning Works, Tools & Legal Basics

Port Scanner: How Port Scanning Works, Tools & Legal Basics

Finding open ports is easy. Here’s how port scans work, when they’re legal in Germany and what has to happen once the scan is done.

The most important thing in brief:

  • A port scanner checks which TCP and UDP ports on a system respond and shows which network services are reachable. It doesn’t tell you whether a service is vulnerable or who owns the system.
  • Scanning your own systems, or systems you have written permission to test, is generally unproblematic in Germany. Without permission, there are legal risks, and the announced reform of the so-called hacker paragraph hasn’t been passed yet.
  • A scan only becomes useful with context: system, service, software version, known vulnerabilities and a responsible person. Since December 2025, handling vulnerabilities has been a legal obligation for organizations in scope of NIS2 in Germany.

Most risky open ports aren’t a hacker problem but an inventory problem. In a warning dated October 28, 2025, Germany’s Federal Office for Information Security (BSI) counted roughly 33,000 Exchange servers with Outlook Web Access exposed to the internet. Of these, 92 percent still ran version 2019 or older, which no longer receives security updates. A port scanner, a specialized type of network scanner, finds open doors like these in minutes. This article explains how port scans work, when they’re legal and what has to happen afterward.

What is a port scanner?

A port scanner is a program that systematically checks which TCP and UDP ports on a host respond. The result shows which network services are reachable on a system and where an attack could start. Port scanner, portscanner and port scanning tool all describe the same thing, and the process itself is called a port scan.

Four tools are often confused, even though they answer different questions:

  • An IP scanner finds out which systems are active in an address range.
  • A port scanner checks which services on those systems are reachable.
  • A vulnerability scanner compares the services it finds against known security flaws.
  • A packet sniffer such as Wireshark doesn’t scan at all. It only records the traffic already crossing the network.

Which port ranges are there?

TCP and UDP each have 65,536 ports, numbered 0 to 65,535. The IANA divides them into three ranges that help when you read a scan result:

  • 0 to 1,023: system or well-known ports for standard services such as SSH (22), HTTP (80) and HTTPS (443).
  • 1,024 to 49,151: registered ports, used for example by databases or RDP (3389).
  • 49,152 to 65,535: dynamic ports that the operating system assigns to outbound connections.

An open port in the dynamic range is often harmless. An open Telnet port 23, on the other hand, is almost always a finding.

How does a port scan work?

A port scan runs in two steps. First, the scanner uses ping, ARP or short TCP requests to find out which hosts respond at all. Then it sends targeted packets to individual ports and evaluates the reaction. The type of response tells it the state of each port.

What states can a port have?

Scanners such as Nmap distinguish three core states:

  • Open: a service accepts connections. For TCP, the target answers a connection request with SYN/ACK.
  • Closed: the system is reachable, but no service is listening. It answers with an RST packet.
  • Filtered: a firewall drops the request. You get no response or only an ICMP error message.

Open means reachable, not vulnerable. Whether an open port is a risk depends on the service, its version and its configuration.

Which scan types are there?

The scan type determines speed, accuracy and the privileges you need. The Nmap documentation on port scanning techniques covers every variant in detail. Four are enough for day-to-day work:

  • TCP SYN scan (half-open): the default. The scanner aborts the handshake after the SYN/ACK. It’s fast but needs administrator or root privileges to send raw packets.
  • TCP connect scan: completes the full connection. It works without special privileges but is slower and shows up in service logs.
  • UDP scan: checks services such as DNS (53) or SNMP (161). Closed ports reply with an ICMP “port unreachable” message, while open ports often don’t reply at all. That’s why UDP scans take much longer.
  • FIN, null and Xmas scans: send unusual TCP flags and rely on RFC-compliant behavior. Windows and many network devices reply with RST regardless of the port state, so the results are useless there.

Modern firewalls and intrusion detection systems (IDS) recognize these patterns anyway. As camouflage, such stealth scans are of little use today.

Then there’s the direction of the scan. A vertical port scan checks many ports on one host. A horizontal port scan, also called a port sweep, checks one port across many hosts. Horizontal scans are typical when someone is hunting for a specific vulnerability, for example every reachable RDP server in a network.

Is port scanning legal?

The legal situation differs by country, and this section covers German law. If you scan your own systems or have the owner’s written permission, you’re generally on safe ground. Things get tricky with third-party networks and no permission. Three sections of the German Criminal Code (StGB) are relevant then.

Section 202a StGB penalizes unauthorized access to data. It requires that someone overcomes a specific access protection. A pure port scan only checks which services respond and generally doesn’t overcome such protection. That’s not a free pass, because whether a scan counts as preparing an attack depends on the individual case.

Section 202c StGB (german), often called the “hacker paragraph,” starts earlier. It already criminalizes producing, obtaining or distributing programs whose purpose is an offense under Section 202a or 202b. Tools such as Nmap generally serve network administration. What matters is what you use them for and against whom.

If an aggressive scan disrupts third-party systems, you also risk an accusation of computer sabotage under Section 303b StGB. Document every scan of third-party systems in writing: client, IP ranges, time window and an emergency contact. This scope agreement protects both sides.

Other jurisdictions have comparable rules, for example the Computer Fraud and Abuse Act in the US and the Computer Misuse Act in the UK. The details differ, so check local law before you scan systems abroad.

This section is an overview and doesn’t replace legal advice.

What changed in 2026?

Germany’s NIS2 Implementation Act has been in force since December 6, 2025. It rewrote the BSI Act (BSIG) and expanded the number of regulated organizations from about 4,500 to about 29,500. Section 30(2) no. 5 BSIG (german) requires security measures that include vulnerability management and disclosure. Regular port scans can therefore form part of the evidence, provided their results are documented and worked through.

The future of the hacker paragraph is still open. In their coalition agreement, the CDU/CSU and SPD announced legal certainty for IT security research. In August 2026, the German Informatics Society (Gesellschaft für Informatik) published a white paper on reforming computer criminal law. Nothing has been passed so far (as of November 2026).

Which port scanner tools are there?

A handful of tools dominate in corporate networks:

  • Nmap: the open source standard for Windows, Linux and macOS. It supports all common scan types, detects service versions (option -sV) and can be extended with the Nmap Scripting Engine. Zenmap is its graphical interface.
  • masscan: built for speed and large address ranges. It delivers a quick overview but fewer details than Nmap.
  • Advanced Port Scanner: a free Windows tool with a graphical interface for quick checks in the local network.
  • Netcat: the all-purpose tool for single connections, for example nc -zv 192.168.0.10 20-80.
  • Online port checkers: test only the public IP address you’re visiting the site from. The target IP and the result end up on the provider’s servers.

Three questions help you choose: How large is the network, how detailed should the result be, and can you export it in a machine-readable format? Throttle the speed in production networks, for example with --max-rate or --scan-delay in Nmap. Otherwise the scan can overload weak devices and trigger false alarms.

How do you check open ports without extra software?

Where you can’t install software, built-in tools are enough for single ports or small ranges. They’re too slow for entire networks, but ideal for a quick double check after a firewall change.

Linux and macOS: checking ports with Bash

bash

for port in {1..1024}; do
 timeout 1 bash -c "echo > /dev/tcp/192.168.0.10/$port" 2>/dev/null \
   && echo "Port $port open"
done

The loop tests ports 1 to 1,024 with a one-second timeout per port. Bash opens a TCP connection to the target port via /dev/tcp. Without the timeout, the loop hangs on filtered ports.

Windows: checking ports with PowerShell (Test-NetConnection)

A single port takes one command:

powershell

Test-NetConnection -ComputerName 192.168.0.10 -Port 3389

Test-NetConnection waits several seconds on filtered ports. For whole ranges, a loop with its own timeout is much faster:

powershell

$ip = "192.168.0.10"
foreach ($port in 1..1024) {
 $client = New-Object System.Net.Sockets.TcpClient
 try {
   if ($client.ConnectAsync($ip, $port).Wait(200)) { "Port $port open" }
 } catch {}
 $client.Dispose()
}

How do you list open ports locally?

Sometimes the simpler question is which services are listening on this machine. On Linux, ss -tulpn lists all open TCP and UDP ports along with the process. To check open ports on Windows, Get-NetTCPConnection -State Listen returns the listening TCP ports, and netstat -ano adds UDP and the process ID. The inside view complements the outside scan, because a firewall can hide a locally open port from the outside.

Which open ports are particularly risky?

Some ports show up in attack reports again and again. An open port on this list needs a justification:

  • 21 (FTP) and 23 (Telnet) transmit credentials in plain text.
  • 445 (SMB) handles Windows file sharing. In 2017, the WannaCry ransomware spread through a flaw in SMBv1.
  • 3389 (RDP) opens remote access to Windows and is a frequent target for password guessing.
  • 1433, 3306 and 5432 belong to Microsoft SQL Server, MySQL and PostgreSQL. Databases don’t belong on the internet.
  • 161 (SNMP v1 and v2) transmits community strings unencrypted.
  • 443 is sensitive on Exchange: the BSI advises against exposing Outlook Web Access openly and recommends limiting it to trusted IP addresses or a VPN.

A hit on this list can only be assessed once it’s clear which system is behind it. In many networks, that’s when the search for host name, location and owner begins. If you build a complete IT inventory, you can answer these questions from your records instead of emailing the entire team.

How do you detect port scans in your own network?

A port scan leaves a typical pattern: many connection attempts from one source to many ports or hosts in a short time. Firewalls, IDS such as Suricata or Snort, and many routers recognize this pattern and can block the source automatically. On some devices, the feature is simply called port scan detection and has to be switched on first.

Individual scans from the internet are routine and mostly automated. Pay attention when a scan comes from inside your own network. An internal scan from an unknown client can point to a compromised device. Forward such events to your SIEM or monitoring system.

Legitimate scans trigger alarms too, for example from inventory or vulnerability scanners. Add their source IP addresses to your monitoring allowlist and agree on time windows. That way, real warnings stay visible.

What should happen after the scan?

A port scan is a snapshot. It gives you a list of IP addresses and ports, nothing more. The list only turns into action once every hit gets context:

  1. Compare against the target state: which ports should be open on this system according to your firewall policy?
  2. Identify the system: which device is behind the IP address, and who is responsible for it?
  3. Check service and version: which software is listening, and is it up to date?
  4. Match vulnerabilities: are there known CVEs for this version, and how severe are they according to CVSS?
  5. Act and record: shut down the service, adjust the firewall rule or patch. Note who does what by when, and justify any risks you deliberately accept.

Steps 2 to 4 take the most time, and a port scanner is the wrong tool for them. The answers are in up-to-date IT documentation. Network documentation software such as Docusnap365 captures systems without agents, including their services, installed software and settings such as firewall and RDP configuration. It maps known CVEs to the affected systems, with a remediation deadline based on the CVSS score and a documented decision.

The scan shows which door is open. Only someone who knows their network can tell whether it should be.

FAQ: frequently asked questions about port scanners

How long does a port scan take?

It depends on scope, scan type and network. By default, Nmap checks the 1,000 most common TCP ports on a host, which usually takes seconds on a local network. A scan of all 65,536 ports or a UDP scan can take anywhere from minutes to hours per host.

How often should companies scan their ports?

There’s no legally prescribed frequency. Check internet-facing systems frequently and after every change to firewalls or services. Internal networks can be scanned at longer intervals, as long as new systems reliably make it into the inventory.

What’s the difference between a port scanner and a vulnerability scanner?

A port scanner shows which services are reachable. A vulnerability scanner such as Greenbone OpenVAS or Nessus goes further and checks those services for known security flaws and misconfigurations. It usually starts with a port scan of its own.

Is Docusnap365 a port scanner?

No. Docusnap365 is a platform for IT documentation, asset management and information security. Its IP-Hosts scan module uses Nmap to detect active systems and their operating systems, but it doesn’t deliver a port audit. Dedicated tools are the right choice for port checks, while Docusnap365 provides the context you need to assess the results.

From open port to completed action

Docusnap365 inventories your network without agents and maps services, software and known CVEs to every system. Owners, deadlines and decisions stay documented and traceable. Try the full Business edition free for 14 days, no credit card required.

Start free trialBook a meeting