Three simple cases of checking whether the remote port is smooth

Source: Internet
Author: User

How can I check whether the remote service has opened tcp port 8000, for example, check whether etiantian.org has enabled tcp port 8000?

Answer: take 80Port as an Example

Method 1: This method is often used to detect whether a remote port is unobstructed.

[Root @ oldboy ~] # Telnet baidu.com 80

Trying 123.125.114.144...

Connected to baidu.com (123.125.114.144 ).

Escape character is '^]'. #=> ctrl +] exit here.

^]

Telnet> quit

Connection closed.

If you write a script to check the port through telnet, use the following method:

[Root @ oldboy ~] # Echo-e "\ n" | telnet baidu.com 80 | grep Connected

Connection closed by foreign host.

Connected to baidu.com (123.125.114.144 ).

Method 2: Use nmap to check whether the port is smooth

[Root @ oldboy ~] # Nmap etiantian.org-p 80

Starting Nmap 4.11 (http://www.insecure.org/nmap/) at PDT

Interesting ports on 211.100.98.99:

PORTSTATE SERVICE

80/tcp openhttp

Nmap finished: 1 IP address (1 host up) scanned in 0.417 seconds

If you write a script to check the port through nmap, use the following method:

26PORT_COUNT = 'map $ ip_add-p $ port | grep open | wc-l'

29 [[$ PORT_COUNT-ge 1] & echo "$ ip_add $ port is OK." | echo "$ ip_add $ port is unknown ."

Method 3: check using nc commands

[Root @ oldboy ~] # Nc-w 5211.100.98.99 80 & echo OK

OK

[Root @ oldboy ~] # Nc-w 108.8.8.8 53 & echo OK | echo no

OK

If you write a script to check the port through nc and monitor the memcache service, use the following method:

ExportoldboyTimestampMemcachedIp = $1
ExportoldboyTimestampMemcachedPort = $2
ExportoldboyTitle = NAGIOS
ExportoldboyTimestampMD5 = 4ED06F8D41B9264OLD0BOY30BE5212BB7E34
ExportwwwServerIp = $3
ExportwwwServerPort = $4

Printf "delete $ oldboyTimestampMD5 \ r \ n" | nc $ oldboyTimestampMemcachedIp $ oldboyTimestampMemcachedPort>/dev/null2> & 1
Sleep1
Judge = ($ (printf "HEAD/oldboy/$ oldboyTitleHTTP/1.1 \ r \ nHost: $5 \ r \ n "| nc $ wwwServerIp $ wwwServerPort | head-n1 | tr" \ r "" \ n "))


This article from the "old boy linux O & M" blog, please be sure to keep this source http://oldboy.blog.51cto.com/2561410/942530

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.