#! /usr/bin/env ruby # # i always forget how to lookup ip by hostname in ruby. following is a little # script which reports on the named hosts, or localhost, by printing a summary # of the ip for each addr family. example usage below # require 'socket' require 'yaml' stdin = ARGV.delete('-') hostnames = ARGV hostsnames += STDIN.readlines if stdin hostnames << 'localhost' if hostnames.empty? report = {} hostnames.each do |hostname| result = {} Socket.getaddrinfo(hostname, 'http').map{|a| result.update a[0] => a[3]} report[hostname] = result end y report __END__ cfp:~ > ip --- localhost: AF_INET6: fe80::1%lo0 AF_INET: 127.0.0.1 cfp:~ > ip www.bit.ly.com --- www.bit.ly.com: AF_INET: 208.73.210.121