Here is two small functions to convert IP addresses from string representation to integer and vice versa.
def inet_aton(ip) ip.split(/\./).map{|c| c.to_i}.pack("C*").unpack("N").first end def inet_ntoa(n) [n].pack("N").unpack("C*").join "." end
Here is two small functions to convert IP addresses from string representation to integer and vice versa.
def inet_aton(ip) ip.split(/\./).map{|c| c.to_i}.pack("C*").unpack("N").first end def inet_ntoa(n) [n].pack("N").unpack("C*").join "." end
Trackbacks are closed.