[20171201]nc快速判斷端口是否打開.txt
--//nc快速判斷端口是否打開,例子:
$ echo exit | nc -w 1 -n -v 192.168.xxx.xx 1521
Connection to 192.168.xxx.xx 1521 port [tcp/*] succeeded!
$ echo exit | nc -w 1 -n -v 192.168.xxx.xx 22
Connection to 192.168.xxx.xx 22 port [tcp/*] succeeded!
SSH-1.99-OpenSSH_3.9p1
Protocol mismatch.
$ echo exit | nc -w 1 -n -v 192.168.xxx.xx 80
Connection to 192.168.xxx.xx 80 port [tcp/*] succeeded!
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>501 Method Not Implemented</title>
</head><body>
<h1>Method Not Implemented</h1>
exit to / not supported.
<hr>
<address>Apache/2.0.52 (Red Hat) Server at 192.168.xxx.xx Port 80</address>
</body></html>
$ echo quit | nc -w 1 -n -v 192.168.xxx.xx 23
Connection to 192.168.xxx.xx 23 port [tcp/*] succeeded!
????
--//關閉23端口測試:
# /etc/rc.d/init.d/xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
nc: connect to 192.168.xxx.xx port 23 (tcp) failed: Connection refused
--//其中-w參數設定逾時.
-w timeout
If a connection and stdin are idle for more than timeout seconds, then the connection is silently closed. The -w
flag has no effect on the -l option, i.e. nc will listen forever for a connection, with or without the -w flag. The
default is no timeout.