Converting IP To Integer
Join the DZone community and get the full member experience.Join For Free
Code to convert ip to integer and vice verse.
def ip2long(ip) long = 0 ip.split(/\./).each_with_index do |b, i| long += b.to_i << ( 8*i ) end long end def long2ip(long) ip =  4.times do |i| ip.push(long.to_i & 255) long = long.to_i >> 8 end ip.join(".") end
Opinions expressed by DZone contributors are their own.