Skip to content

Instantly share code, notes, and snippets.

@samstokes
Created November 9, 2010 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samstokes/669022 to your computer and use it in GitHub Desktop.
Save samstokes/669022 to your computer and use it in GitHub Desktop.
Converts an IP address from 'dotted string' representation to a 32-bit integer.
def ip2int(dotted)
dotted.split('.').map(&:to_i).
zip([24, 16, 8, 0]).
inject(0) do |s, (segment, shift)|
s + (segment << shift)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment