如何扫描网址ip的特定端口或扫描全部网段

一 nc
sudo apt install netcat-openbsd

$nc -vz  baidu.com 80
Connection to baidu.com (39.156.66.10) 80 port [tcp/http] succeeded!

$nc -h
nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl]
	  [-m minttl] [-O length] [-P proxy_username] [-p source_port]
	  [-q seconds] [-s sourceaddr] [-T keyword] [-V rtable] [-W recvlimit]
	  [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]]
	  [destination] [port]
	  
-v 	verbose
-z     Zero-I/O mode	  

或sudo apt install ncat

$ ncat -vz  baidu.com 80
Ncat: Version 7.80 ( https://nmap.org/ncat )
Ncat: Connected to 110.242.68.66:80.
Ncat: 0 bytes sent, 0 bytes received in 0.27 seconds.

二 telnet
sudo apt install telnet

$telnet 192.168.2.61 22
Trying 192.168.2.61...
Connected to 192.168.2.61.
Escape character is '^]'.
SSH-2.0-OpenSSH_9.5

转义符为 ‘^]’.
ctrl + ] 之后quit 或 q

$telnet baidu.com 80
Trying 39.156.66.10...
Connected to baidu.com.
Escape character is '^]'.
^]
telnet> q
Connection closed.

$telnet baidu.com 443
Trying 110.242.68.66...
Connected to baidu.com.
Escape character is '^]'.
^]
telnet> q
Connection closed.

三 nmap

$ nmap baidu.com -p 443
Starting Nmap 7.80 ( https://nmap.org ) at 2024-01-17 08:06 CST
Nmap scan report for baidu.com (110.242.68.66)
Host is up (0.023s latency).
Other addresses for baidu.com (not scanned): 39.156.66.10

PORT    STATE SERVICE
443/tcp open  https

Nmap done: 1 IP address (1 host up) scanned in 0.21 seconds

扫描TCP开放端口

$nmap -sT baidu.com
PORT    STATE SERVICE
80/tcp  open  http
443/tcp open  https

扫描UDP开放端口 需root权限

$nmap -sU baidu.com

nmap 扫描整个网段

nmap -sn 192.168.1.0/24
Starting Nmap 7.80 ( https://nmap.org ) at 2024-01-17 08:07 CST
Nmap scan report for 192.168.1.1
Host is up (0.0022s latency).
Nmap scan report for 192.168.1.2
Host is up (0.0046s latency).
Nmap scan report for 192.168.1.5
Host is up (0.0032s latency).
Nmap done: 256 IP addresses (3 hosts up) scanned in 6.96 seconds

你可能感兴趣的:(tcp/ip,网络协议,网络,运维)