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