Guest User

Untitled

a guest
Jul 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. # yeah, yeah, ipv6 not supported. This is a quick hack.
  4.  
  5. unless hostname = ARGV.first
  6. puts "usage: gethostbyname HOSTNAME"
  7. end
  8.  
  9. require 'socket'
  10. packed_addr = Socket.gethostbyname(hostname).last
  11. ip_int = packed_addr.unpack("N").last
  12. octets = (1..4).map {|i| (ip_int % (256 ** i)) / (256 ** (i - 1) ) }.reverse
  13. puts octets.join(".")
Add Comment
Please, Sign In to add comment