Created
April 23, 2012 03:10
-
-
Save hugoduncan/2468613 to your computer and use it in GitHub Desktop.
Test for a reachable port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn port-reachable? | |
([ip port timeout] | |
(let [socket (doto (java.net.Socket.) | |
(.setReuseAddress false) | |
(.setSoLinger false 1) | |
(.setSoTimeout timeout))] | |
(try | |
(.connect socket (java.net.InetSocketAddress. ip port)) | |
true | |
(catch java.io.IOException _) | |
(finally | |
(try (.close socket) (catch java.io.IOException _)))))) | |
([ip port] | |
(port-reachable? ip port 2000))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment