Created
March 21, 2010 11:28
-
-
Save pervognsen/339248 to your computer and use it in GitHub Desktop.
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
(ns port-scanner | |
(:import [java.net Socket InetSocketAddress])) | |
(defn port-open? [hostname port timeout] | |
(try | |
(with-open [sock (Socket.)] | |
(.connect sock (InetSocketAddress. hostname port) timeout) | |
port) | |
(catch Exception e false))) | |
(let [hostname (or (first *command-line-args*) | |
(do (println "Usage: scanner <hostname>") | |
(System/exit 1)))] | |
(println (str "Scanning " hostname "...")) | |
(doseq [port (doall (map #(future (port-open? hostname % 5000)) (range 1 1024)))] | |
(when @port (println @port "is open")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment