Skip to content

Instantly share code, notes, and snippets.

@rmarchei
Created June 17, 2016 06:24
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 rmarchei/f1f22089968f5f48e2f15a7d53aafa74 to your computer and use it in GitHub Desktop.
Save rmarchei/f1f22089968f5f48e2f15a7d53aafa74 to your computer and use it in GitHub Desktop.
Test if an IP is public
def is_public?(ip)
["127.0.0.0/8", "192.168.0.0/16", "172.16.0.0/12", "10.0.0.0/8"].map { |net| (IPAddr.new net).include?(IPAddr.new ip) }.none?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment