How Linux detects port connectivity in bulk and whether ports are open

Source: Internet
Author: User

Is there a method for batch inspection? Some. We use NC to quickly detect the openness of the port.

The use of the NC detection port

Nc-z-W 10-u%ip%%PORT%

-Z indicates detection or scanning of ports
-W indicates time-out
-U means that the UDP protocol is used, and this parameter is NULL for the TCP protocol

For example:

[@s136. ipcpu.com ~]# nc-z-W 10-u 8.8.8.8 53Connection to 8.8.8.8, Port [Udp/domain] succeeded! [@s136. ipcpu.com ~]# nc-z-W 8.8.8.8 53Connection to 8.8.8.8, Port [Tcp/domain] succeeded! [@s136. ipcpu.com ~]# Echo $?0[@s136. ipcpu.com ~]# nc-z-w 8.8.8.7 53[@s136. ipcpu.com ~]# Echo $?1

Port successfully unicom return value is 0, prompt succeeded; otherwise return 1 without prompting any data

Suppose we had such a heap of IPs and ports.

#cat ports119.181.69.96 8080119.181.118.38 8000119.181.20.18 8080119.181.69.37 8080

We can write such a script to detect whether the port is open in bulk:

Cat Tetsport   |  While read Linedo #nc-Z-  w  $linenc-Z-w $line >/dev/null 2>&1if [$?-eq 0]thenecho $line: Okel Seecho $line: Failfi Done

Well, here's how we run the results:

119.181.69.96 8080:ok119.181.118.38 8000:ok119.181.20.18 8080:fail119.181.69.37 8080:ok

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.