Created
June 17, 2016 06:24
-
-
Save rmarchei/f1f22089968f5f48e2f15a7d53aafa74 to your computer and use it in GitHub Desktop.
Test if an IP is public
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
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