Skip to content

Instantly share code, notes, and snippets.

@s0what
Created June 1, 2010 02:55
Show Gist options
  • Save s0what/420509 to your computer and use it in GitHub Desktop.
Save s0what/420509 to your computer and use it in GitHub Desktop.
require "ipaddr"
def ip2int(ip)
IPAddr.new(ip).to_i
end
def int2ip(int)
IPAddr.new(int, Socket::AF_INET).to_s
end
def ip_without_last(ip)
ip.gsub(/\.[0-9]{1,3}$/, ".*")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment