Nmap is a very useful and popular tool used to scan ports. Nmap by default scans the most popular 1000 ports. We may need to change the port range and protocol type to all while scanning with Nmap.
Nmap是用于扫描端口的非常有用且流行的工具。 默认情况下,Nmap扫描最流行的1000个端口。 使用Nmap扫描时,我们可能需要将端口范围和协议类型全部更改。
扫描具有范围的所有TCP端口 (Scan All TCP Ports with Range)
We can specify the port range with the -p
option. As we know TCP port numbers are between and
65535
. We will use -p0-65535
as an option in order to scan all TCP ports. We do not specify the TCP protocol because the default protocol for Nmap port scan is TCP.
我们可以使用-p
选项指定端口范围。 我们知道TCP端口号介于和
65535
。 我们将使用-p0-65535
作为选项,以扫描所有TCP端口。 我们未指定TCP协议,因为Nmap端口扫描的默认协议为TCP。
$ nmap -p0-65535 192.168.122.1
更快扫描所有端口 (Faster Scan For All Ports)
If we are scanning all ports this will take a lot of time. If the situation is not critical we can use a faster scan with -T5
parameter. This is the fastest scan level for Nmap. This option can be used for UDP scans too.
如果我们要扫描所有端口,则将花费大量时间。 如果情况不是很紧急,我们可以使用带有-T5
参数的更快扫描。 这是Nmap最快的扫描级别。 此选项也可用于UDP扫描。
$ nmap -p0-65535 192.168.122.1 -T5

扫描所有TCP端口(Scan All TCP Ports)
Another way to specify all TCP ports is a dash. We can use -p-
which is more practical then port range specification.
指定所有TCP端口的另一种方法是破折号。 我们可以使用-p-
,它比端口范围规范更实用。
$ nmap -p- 192.168.122.1
扫描具有范围的所有UDP端口 (Scan All UDP Ports with Range)
Nmap uses TCP as the default protocol for the port scan. We should explicitly specify the UDP protocol for the UDP port scan. We will use the same port range specification used in TCP. We will use -sU
for UDP protocol specification.
Nmap使用TCP作为端口扫描的默认协议。 我们应该为UDP端口扫描明确指定UDP协议。 我们将使用与TCP相同的端口范围规范。 我们将-sU
用于UDP协议规范。
$ nmap -sU -p0-65535 192.168.122.1
扫描所有UDP端口 (Scan All UDP Ports)
We can also scan all UDP ports by using the -sU
option. We will use -p-
to specify all ports easily. -p-
express all ports from 0 to 65535. UDP scan is slow and takes some time to complete.
我们还可以使用-sU
选项扫描所有UDP端口。 我们将使用-p-
轻松指定所有端口。 -p-
表示从0到65535的所有端口。UDP扫描速度很慢,需要一些时间才能完成。
$ nmap -sU -p- 192.168.122.1
扫描所有TCP UDP端口 (Scan All TCP UDP Ports)
We can scan all UDP and TCP ports in a single command. We will use -sU
for UDP and sT
for TCP protocol. We will also specify the port range we want to scan which is all TCP and UDP ports that start from 0 to 65535. This will scan all 65535 ports of TCP and UDP for the specified remote host or IP address. Keep in mind that this will take some time because especially UDP scan is slow according to the TCP scan. We will also provide root privileges with the sudo
command.
我们可以在一个命令中扫描所有UDP和TCP端口。 我们将-sU
用于UDP,将sT
用于TCP协议。 我们还将指定要扫描的端口范围,即从0到65535开始的所有TCP和UDP端口。这将扫描TCP和UDP的所有65535端口以查找指定的远程主机或IP地址。 请记住,这会花费一些时间,因为根据TCP扫描,尤其是UDP扫描速度很慢。 我们还将通过sudo
命令提供root特权。
$ sudo nmap -sU -sT -p0-65535 192.168.122.1
翻译自: https://www.poftut.com/how-to-scan-all-tcp-and-udp-ports-with-nmap/