Created
November 9, 2010 12:19
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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