Skip to content

Instantly share code, notes, and snippets.

View terencebor's full-sized avatar
🏠
Working from home

tarasbor terencebor

🏠
Working from home
View GitHub Profile
@bmc
bmc / rfc1918.rb
Created May 19, 2012 01:06
Quick and dirty Ruby module to determine if IP address (as string) is RFC-1918 address
module RFC1918
def is_rfc1918_address(ip)
unless ip =~ /^(\d{1,3}).(\d{1,3}).(\d{1,3}).(\d{1,3})$/
raise "#{ip} is not an IP address"
end
octets = [$1, $2, $3, $4].map &:to_i
raise "#{ip} is a bad IP address" unless octets.all? {|o| o < 256}
# The Internet Assigned Numbers Authority (IANA) has reserved the