Skip to content

Instantly share code, notes, and snippets.

@qsun
Created September 28, 2011 08:49
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save qsun/1247402 to your computer and use it in GitHub Desktop.
Save qsun/1247402 to your computer and use it in GitHub Desktop.
ruby integer to/from ip address
require 'ipaddr'
IPAddr.new('1.2.3.4').to_i
IPAddr.new(16909060, Socket::AF_INET).to_s
@zavan
Copy link

zavan commented May 19, 2022

For IP v6 use Socket::AF_INET6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment