[20171201]nc快速判斷埠是否開啟.txt

lfree發表於2017-12-01

[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  ]

$ echo quit | nc -w 1 -n -v  192.168.xxx.xx 23
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.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2148121/,如需轉載,請註明出處,否則將追究法律責任。

相關文章