Skip to content

Instantly share code, notes, and snippets.

@m0smith
Last active December 16, 2015 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m0smith/5510954 to your computer and use it in GitHub Desktop.
Save m0smith/5510954 to your computer and use it in GitHub Desktop.
Get a list of active IP addresses for this host
(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