Use the netcat [nc] command to scan ports in Linux and Unix

Source: Internet
Author: User

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:

  1. ### Syntax ###
  2. ### nc -z -v {host-name-here} {port-range-here}
  3. nc -z -v host-name-here ssh
  4. nc -z -v host-name-here 22
  5. nc -w1-z -v server-name-here port-Number-her
  6. ### Scan Port 1 to port 1023 ###
  7. nc -zv vip-1.vsnl.nixcraft.in1-1023

Output example:

  1. Connection to localhost 25 port [tcp/smtp] succeeded!
  2. Connection to vip-1.vsnl.nixcraft.in25 port [tcp/smtp] succeeded!
  3. Connection to vip-1.vsnl.nixcraft.in80 port [tcp/http] succeeded!
  4. Connection to vip-1.vsnl.nixcraft.in143 port [tcp/imap] succeeded!
  5. Connection to vip-1.vsnl.nixcraft.in199 port [tcp/smux] succeeded!
  6. Connection to vip-1.vsnl.nixcraft.in783 port [tcp/*] succeeded!
  7. Connection to vip-1.vsnl.nixcraft.in 904 port [tcp/vmware-authd] succeeded!
  8. Connection to vip-1.vsnl.nixcraft.in 993 port [tcp/imaps] succeeded!

You can also scan a Single Port:

  1. nc -zv v.txvip1 443
  2. nc -zv v.txvip1 80
  3. nc -zv v.txvip1 22
  4. nc -zv v.txvip1 21
  5. nc -zv v.txvip1 smtp
  6. nc -zvn v.txvip1 ftp
  7. ### Use a 1-second timeout value for faster scanning ###
  8. 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

  1. -Z: the port scan mode is zero I/O.
  2. -V: displays detailed information. [Use-vv to output more detailed information.]
  3. -N: Use a Pure Digital IP address, that is, DNS is not used to resolve the IP address.
  4. -W 1: Set the timeout value to 1.

More examples:

  1. $ netcat -z -vv www.cyberciti.biz http
  2. www.cyberciti.biz [75.126.153.206]80(http) open
  3. sent 0, rcvd 0
  4. $ netcat -z -vv google.com https
  5. DNS fwd/rev mismatch: google.com != maa03s16-in-f2.1e100.net
  6. DNS fwd/rev mismatch: google.com != maa03s16-in-f6.1e100.net
  7. DNS fwd/rev mismatch: google.com != maa03s16-in-f5.1e100.net
  8. DNS fwd/rev mismatch: google.com != maa03s16-in-f3.1e100.net
  9. DNS fwd/rev mismatch: google.com != maa03s16-in-f8.1e100.net
  10. DNS fwd/rev mismatch: google.com != maa03s16-in-f0.1e100.net
  11. DNS fwd/rev mismatch: google.com != maa03s16-in-f7.1e100.net
  12. DNS fwd/rev mismatch: google.com != maa03s16-in-f4.1e100.net
  13. google.com [74.125.236.162]443(https) open
  14. sent 0, rcvd 0
  15. $ netcat -v -z -n -w1192.168.1.2541-1023
  16. (UNKNOWN)[192.168.1.254]989(ftps-data) open
  17. (UNKNOWN)[192.168.1.254]443(https) open
  18. (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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.