Last active
December 16, 2015 22:59
-
-
Save m0smith/5510954 to your computer and use it in GitHub Desktop.
Get a list of active IP addresses for this host
This file contains hidden or 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))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment