Skip to content

Instantly share code, notes, and snippets.

@rymndhng
Created October 27, 2019 16:28
Show Gist options
  • Save rymndhng/b23f5136e78e86cfbef8c55687ed30b8 to your computer and use it in GitHub Desktop.
Save rymndhng/b23f5136e78e86cfbef8c55687ed30b8 to your computer and use it in GitHub Desktop.
Check if the host is in a private range
(defn allowed-host?
"Checks whether the given Inet Address for outbound request is allowed"
[^java.net.InetAddress inet-addr]
(try
(not (or (.isLinkLocalAddress inet-addr) ; 169.0.0.0/8
(.isLoopbackAddress inet-addr) ; 127.0.0.1
(.isAnyLocalAddress inet-addr) ; 0.0.0.0
(.isMulticastAddress inet-addr) ; 224.0.0.0 to 239.255.255.255
(.isSiteLocalAddress inet-addr) ; 10.0.0.0/8, 192.168.0.0/16
))
(catch Exception e
false)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment