Use the netcat [nc] command to scan ports in Linux and Unix
How can I find out which ports are open on my server? How can I use the nc command for port scanning to replace the nmap command in Linux or Unix?
Nmap ("Network Mapper") is an open-source tool for Network detection and security audit. If nmap is not installed or you do not want to use nmap, you can use the netcat/nc command for port scanning. It is very useful for checking which ports on the target computer are open or running services. You can also use the nmap command for port scanning.
How can I use nc to scan ports on Linux, UNIX, and Windows servers?
If nmap is not installed, try the nc/netcat Command, as shown below. The-z parameter is used to tell the nc to report the opened port instead of starting the connection. When using the-z parameter in the nc command, you need to limit the port range and speed up the running after the host name/ip Address:
### Syntax ###
### nc -z -v {host-name-here} {port-range-here}
nc -z -v host-name-here ssh
nc -z -v host-name-here 22
nc -w1-z -v server-name-here port-Number-her
### Scan Port 1 to port 1023 ###
nc -zv vip-1.vsnl.nixcraft.in1-1023
Output example:
Connection to localhost 25 port [tcp/smtp] succeeded!
Connection to vip-1.vsnl.nixcraft.in25 port [tcp/smtp] succeeded!
Connection to vip-1.vsnl.nixcraft.in80 port [tcp/http] succeeded!
Connection to vip-1.vsnl.nixcraft.in143 port [tcp/imap] succeeded!
Connection to vip-1.vsnl.nixcraft.in199 port [tcp/smux] succeeded!
Connection to vip-1.vsnl.nixcraft.in783 port [tcp/*] succeeded!
Connection to vip-1.vsnl.nixcraft.in 904 port [tcp/vmware-authd] succeeded!
Connection to vip-1.vsnl.nixcraft.in 993 port [tcp/imaps] succeeded!
You can also scan a Single Port:
nc -zv v.txvip1 443
nc -zv v.txvip1 80
nc -zv v.txvip1 22
nc -zv v.txvip1 21
nc -zv v.txvip1 smtp
nc -zvn v.txvip1 ftp
### Use a 1-second timeout value for faster scanning ###
netcat -v -z -n -w1 v.txvip1 1-1023
Output example:
Figure 01: Linux/Unix: Use Netcat to test the connection between TCP and UDP and the server
- -Z: the port scan mode is zero I/O.
- -V: displays detailed information. [Use-vv to output more detailed information.]
- -N: Use a Pure Digital IP address, that is, DNS is not used to resolve the IP address.
- -W 1: Set the timeout value to 1.
More examples:
$ netcat -z -vv www.cyberciti.biz http
www.cyberciti.biz [75.126.153.206]80(http) open
sent 0, rcvd 0
$ netcat -z -vv google.com https
DNS fwd/rev mismatch: google.com != maa03s16-in-f2.1e100.net
DNS fwd/rev mismatch: google.com != maa03s16-in-f6.1e100.net
DNS fwd/rev mismatch: google.com != maa03s16-in-f5.1e100.net
DNS fwd/rev mismatch: google.com != maa03s16-in-f3.1e100.net
DNS fwd/rev mismatch: google.com != maa03s16-in-f8.1e100.net
DNS fwd/rev mismatch: google.com != maa03s16-in-f0.1e100.net
DNS fwd/rev mismatch: google.com != maa03s16-in-f7.1e100.net
DNS fwd/rev mismatch: google.com != maa03s16-in-f4.1e100.net
google.com [74.125.236.162]443(https) open
sent 0, rcvd 0
$ netcat -v -z -n -w1192.168.1.2541-1023
(UNKNOWN)[192.168.1.254]989(ftps-data) open
(UNKNOWN)[192.168.1.254]443(https) open
(UNKNOWN)[192.168.1.254]53(domain) open
You can also see:
- Use the nmap command to scan open ports in the network.
- Manual page-nc (1), nmap (1)
Via: http://www.cyberciti.biz/faq/linux-port-scanning/
Author: Vivek Gite Translator: strugglingyouth Proofreader: wxy
This article was originally compiled by LCTT and launched with the honor of Linux in China
This article permanently updates the link address: