Created
August 20, 2010 19:37
-
-
Save samullen/540976 to your computer and use it in GitHub Desktop.
Testing IP's against CIDR. Whitelisting blocks.
This file contains 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
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'ipaddr' | |
cidr = IPAddr.new("172.20.0.0") | |
# cidr = IPAddr.new("198.6.5.0") | |
mask = 16 | |
# ip = IPAddr.new("198.6.5.22") | |
ip = IPAddr.new("172.20.155.101") | |
puts ip.to_i | |
puts cidr.to_i | |
puts ip.to_i & ~((1 << (32 - mask)) - 1) == cidr.to_i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment