Port Scanning: What It Is and When It Is Legal
What a port scan reveals, how to scan your own network responsibly, and why written permission decides whether it is acceptable.
Key takeaways
- A port scan reports which doors on a machine answer, which is the first thing both defenders and intruders want to know.
- Results are usually described as open, closed or filtered, based on how the target responds.
- Written authorization from the owner is the clearest line between a security test and trouble.
- Laws differ between countries and are interpreted case by case, so do not assume that a harmless intention protects you.
- Regularly scanning your own public addresses is one of the cheapest ways to catch accidental exposure.
A port scan sends connection attempts to a machine to find out which network services are listening on it. Scanning systems you own, or have clear written permission to test, is ordinary administration. Scanning other people's systems without permission can break laws, contracts or acceptable use policies, and whether it does depends on where you are, where the target is and what you do next.
This article explains what scans reveal, how to check your own network, and where the lines tend to fall. It is general information, and a lawyer is the right source for a specific situation.
Ports in one minute
An IP address identifies a machine or network interface. A port number, from 0 to 65535, identifies a particular service on it. Web servers commonly listen on 80 and 443, SSH on 22, and Windows remote desktop on 3389. The full explanation is in how one computer runs many services.
A port is "open" only because some program is waiting for connections there. Each open port is a piece of software that can be spoken to, which means it can have bugs, weak passwords or configuration mistakes.
How a scan works
The simplest TCP scan tries to connect to each port and notes what comes back. TCP starts with a three-step handshake: the client sends a SYN, a listening service replies with SYN-ACK, and the client finishes with ACK. A machine with nothing listening on that port normally replies with a reset (RST). A firewall that silently drops the packet produces no reply at all.
UDP has no handshake, so UDP scanning is slower and less certain. A reply shows something is there. An ICMP "port unreachable" message suggests the port is closed. Silence could mean either an open service ignoring an unexpected probe or a firewall dropping it.
Scanners can go further, reading a service's greeting banner or sending protocol-specific probes to guess the software and version. Treat those guesses with caution, since banners can be changed and patched packages often keep older version numbers.
Scanning your own network
Nmap is the widely used open-source scanner, available for Windows, macOS and Linux. Run these only against devices you own or are authorized to test. The addresses below are examples from private and documentation ranges.
# Which devices answer on my local network?
nmap -sn 192.168.1.0/24
# Common ports on one device
nmap 192.168.1.10
# Specific ports, with service and version detection
nmap -sV -p 22,80,443,3389 192.168.1.10
# Every TCP port, which takes longer
nmap -p- 192.168.1.10 Without Nmap, you can test one port at a time. In Windows PowerShell:
Test-NetConnection 192.168.1.10 -Port 443 On Linux or macOS with netcat installed:
nc -vz 192.168.1.10 443 There is more in testing a port from the command line. To work out which addresses a range such as a /24 covers before you scan it, use the CIDR calculator. A mistyped prefix length can point a scan at many more machines than you intended.
Inside view and outside view
A scan from your own desk shows what neighbors on the local network can reach. A scan of your public address from a different connection shows what the internet can reach, which is often a very different list. Both are worth doing. Check your internet provider's and hosting provider's rules first, since some restrict scanning or want notice.
Doing something with the results
For every open port, ask three questions. What program is this? Does anyone need it? Who should be able to reach it? Then act:
| Finding | Reasonable response |
|---|---|
| Service nobody recognizes | Identify the device and process before anything else |
| Service no longer needed | Stop and disable it |
| Needed only internally | Block it at the edge and check for forgotten port forwards |
| Needed from outside | Patch it, require strong sign-in, restrict sources if possible |
| Remote desktop or database open publicly | Close it and provide access through a VPN or gateway |
Home users often find forgotten forwarding rules or devices that opened ports automatically. See UPnP and its risks.
What a scan can and cannot tell you
A clean result is encouraging, and it is easy to read too much into it.
A scan describes one moment from one vantage point. A service that starts only during business hours, or a forwarding rule that a game console creates on demand, may be absent when you look. A firewall that allows only certain source addresses will look closed from everywhere else, which is the intent, but you should know which view you tested.
Version detection is inference. Operating system vendors often apply security fixes to an older release without changing the number it reports, so a banner that looks outdated may be patched. The reverse also happens: a current-looking banner says nothing about a weak password or a dangerous setting.
A port scan also says nothing about the web application behind port 443, the strength of anyone's sign-in or the software on machines that only make outbound connections. Those need other checks, and vulnerability scanning and penetration testing cover more of that ground.
Finally, remember IPv6. If your network has it, devices may have globally reachable IPv6 addresses even though they share one IPv4 address. Confirm that your firewall blocks unsolicited inbound IPv6 too, and scan those addresses explicitly, using the -6 option in Nmap. Sweeping a whole IPv6 subnet is impractical because of its size, so work from your router's list of known devices.
When is it legal?
No single worldwide rule says "port scanning is legal" or "illegal." Most countries have computer misuse laws that focus on unauthorized access or interference with systems. Examples include the Computer Fraud and Abuse Act in the United States and the Computer Misuse Act 1990 in the United Kingdom. How such laws apply to scanning alone has been argued differently in different places, and some jurisdictions also restrict making or supplying hacking tools in certain circumstances.
Several things beyond criminal law matter:
- Contracts and policies. Your internet provider, cloud host, school or employer may prohibit scanning regardless of what criminal law says. Breaking those terms can cost you service, a job or enrollment.
- Disruption. An aggressive scan can overwhelm fragile equipment such as old industrial controllers or printers. Causing damage changes the picture considerably.
- What follows. Trying a default password on a service you discovered is an access attempt, a clearly more serious act.
- Shared infrastructure. A website may run on a provider's machines shared with others. The site owner cannot always authorize testing of systems they do not own.
The safe practice is simple: no permission, no scan. For learning, use your own equipment, virtual machines on your own computer, or training platforms that explicitly invite testing. A home lab gives you plenty of targets.
What good authorization looks like
For work, get it in writing before the first packet. A useful authorization names the person granting it and their authority, lists the exact addresses and domain names in scope, states dates and allowed hours, describes permitted techniques, names contacts for both sides and says what happens to the findings. Where third parties host the systems, follow their testing policy too.
Researchers who look for flaws in other organizations' products should rely on published disclosure policies. Bug bounties and responsible disclosure explains how scope and safe harbor language work, and cybercrime law and good-faith research covers the legal side.
Being on the receiving end
Any public address is scanned routinely, by researchers, search services that catalog exposed devices and people looking for victims. Seeing scans in your firewall logs is normal and rarely needs a response. What matters is what they find.
Keep unnecessary ports closed, set your firewall to drop unsolicited inbound traffic by default, and patch the services you must expose. Rate limiting and automatic blocking reduce noise. If one source hammers a particular service or follows a scan with login attempts, record it and consider reporting it to the network that owns the address.
Common questions
Is a scan the same as an attack?
By itself it gathers information. It is often the first stage of an attack, which is why some networks treat unexpected scanning as hostile and block the source.
Can I scan a site just to see if it is secure before using it?
Not without permission. Judge it by public signals instead, such as its published security policy, how it handles sign-in and whether it supports multi-factor authentication.
Why do my results differ between two scans?
Firewalls may rate limit or block a scanner partway through, packets get lost, and services start and stop. Repeat more slowly and compare.