Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn get-ip []
- "Return the first IPv4 address which IS NOT the localhost (\"127.0.0.1\")"
- (let [IP-list
- (for [inter (enumeration-seq (java.net.NetworkInterface/getNetworkInterfaces))]
- (for [ip (enumeration-seq (.getInetAddresses inter))]
- (.getHostAddress ip)))
- IPv4-list (map #(re-matches #"\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?" %)
- (flatten IP-list))]
- (first (remove #(or (= "127.0.0.1" %) (= nil %)) IPv4-list))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement