Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # yeah, yeah, ipv6 not supported. This is a quick hack.
- unless hostname = ARGV.first
- puts "usage: gethostbyname HOSTNAME"
- end
- require 'socket'
- packed_addr = Socket.gethostbyname(hostname).last
- ip_int = packed_addr.unpack("N").last
- octets = (1..4).map {|i| (ip_int % (256 ** i)) / (256 ** (i - 1) ) }.reverse
- puts octets.join(".")
Add Comment
Please, Sign In to add comment