One: Telnet
This method is often used to detect whether a remote port is unobstructed.
[[Email protected] ~]# Telnet baidu.com 80
Trying 123.125.114.144 ...
Connected to Baidu.com (123.125.114.144). #==> appeared connected express connectivity, indicating that Baidu's 80 port open
Escape character is ' ^] '. #==>ctrl+] exit here.
^]
Telnet> quit
Connection closed.
If the write script checks the port via Telnet, the following method can be used:
[Email protected] ~]# echo-e "\ n" |telnet baidu.com 80|grep Connected
Connection closed by foreign host.
Connected to Baidu.com (123.125.114.144).
Second: through Nmap to check whether the port is unobstructed
[[email protected] ~]# Nmap etiantian.org-p 80
Starting Nmap 4.11 (http://www.insecure.org/nmap/) at 2012-07-22 17:22 PDT
Interesting ports on 211.100.98.99:
PORT State SERVICE
80/TCP Open http
Nmap finished:1 IP Address (1 host up) scanned in 0.417 seconds
If you write a script through Nmap Check port can use the following method:
Port_count= ' Nmap $ip _add-p $port |grep open|wc-l '
[[$PORT _count-ge 1]] && echo $ip _add $port is ok. "| | echo "$ip _add $port is unknown."
: Check by NC command
[[email protected] ~]# nc-w 5 211.100.98.99 && echo OK
Ok
[[email protected] ~]# nc-w 8.8.8.8 && echo OK | | Echo No
Ok
If the write script checks the port through the NC and monitors the Memcache service, the following method can be used:
Export oldboytimestampmemcachedip=$1
Export oldboytimestampmemcachedport=$2
Export Oldboytitle=nagios
Export Oldboytimestampmd5=4ed06f8d41b9264old0boy30be5212bb7e34
Export wwwserverip=$3
Export wwwserverport=$4
printf "Delete $oldboyTimestampMD 5\r\n" | NC $oldboyTimestampMemcachedIp $oldboyTimestampMemcachedPort >/dev/null 2>&1
Sleep 1
Judge= ($ (printf "head/oldboy/$oldboyTitle http/1.1\r\nhost: $5\r\n\r\n" | NC $wwwServerIp $wwwServerPort | head-n1|tr "\ R "" \ n "))
Iv. check_tcp and CHECK_UDP of NAGIOS
Use:
Check_tcp-h Host-P Port-W < warning time;]
[-c]
[-s < send string;]
[-E]
[-Q]
[-M]
[-D < delay;]
[-T
[-R]
[-M] [-V] [-4 |-6] [-j]
[-D,]
[-S] [-E]
Check_udp
Use:
CHECK_UDP Host-P port
Check_udp-h-W < warning time;]
[-c]
[-s < send string;]
[-E]
[-Q]
[-M]
[-D < delay;]
[-T
[-R]
[-M] [-V] [-4 |-6] [-j]
[-D,] [-S] [-E]
Item?? :
-H,-help
Print a detailed help screen
-V,-?? Version
Print version Information
-H,-host name = ADDRESS
Host name, IP address, or UNIX socket (must be an absolute path)
-P,-port = INTEGER
Port number (default: None)
-4-Using the IPV4
Connect using IPV4
-6-Using the IPV6
Connect using IPV6
-E,-escape
You can use \ n \ r \ t to send or exit strings. Must appear in the Send or exit options
Default value: No send, \ r \ n End exit
-S,-= string send
String sent to the server
-E,-expected = STRING
Expected string in server response (repeatable)
-A,-all
All expected strings must appear in response to the server. Default is any
-Q,-Quit smoking = STRING
Send server initiates a clean close connection string
-R,-Deny OK | warning | Critical hit OK, accept TCP deny warning to all countries, critical hit (default: Critical Hit)
-M,-mismatch = OK | warning | critical hit
Accept expected string mismatch status OK, warning, critical hit (default: Warn)
-j,-prison
Hidden output from TCP sockets
-M,-maxbytes = INTEGER
Close the connection once more than this number of bytes received
-D,-delay = INTEGER
Wait time between seconds to send string and poll response
-D,-certificate = Integer,integer]
The minimum number of days the certificate is valid.
A # Day warning, the second time is key (if 0 is not specified).
-S,-SSL
A connection that uses SSL.
-W,-warning = DOUBLE
Response time (seconds) that caused the warning state
-C,-key = DOUBLE
Response time in critical state (seconds)
-T,-timeout = INTEGER
Seconds, and then the connection time-out (default: 10)
-V,-?? Verbose details
Displays command-line debugging details (Nagios, may truncate output)
The interface assembly parameter format is as follows a total of 4 elements:
Command! port! Alarm delay! Critical alarm delay! Connection time-out
Check_tcp!23!0.0020!0.0050!10
Note:
check_imap=check_tcp!143
Check_ftp=check_tcp!21
check_nntp=check_tcp!119
check_pop=check_udp!110
Check_udp=check_tcp
Check_telnet=check_tcp!23
Telnet detects if the port is unblocked