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
(import (java.net NetworkInterface Inet4Address)) | |
(defn ip-filter [inet] | |
(and (.isUp inet) | |
(not (.isVirtual inet)) | |
(not (.isLoopback inet)))) | |
(defn ip-extract [netinf] | |
(let [inets (enumeration-seq (.getInetAddresses netinf))] | |
(map #(vector (.getHostAddress %1) %2) (filter #(instance? Inet4Address %) inets ) (repeat (.getName netinf))))) | |
(defn ips [] | |
(let [ifc (NetworkInterface/getNetworkInterfaces)] | |
(mapcat ip-extract (filter ip-filter (enumeration-seq ifc))))) |