From 6b777872b8d0ec8506ef90bc121eb70a8099db80 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Thu, 22 Nov 2012 06:42:07 +0000 Subject: Renamed. --- lib/custodian/dnsutil.rb | 72 ------------------------------------------------ 1 file changed, 72 deletions(-) delete mode 100644 lib/custodian/dnsutil.rb (limited to 'lib/custodian/dnsutil.rb') diff --git a/lib/custodian/dnsutil.rb b/lib/custodian/dnsutil.rb deleted file mode 100644 index e42d5e3..0000000 --- a/lib/custodian/dnsutil.rb +++ /dev/null @@ -1,72 +0,0 @@ - - -require 'ipaddr' -require 'socket' -require 'timeout' - - - -# -# This class is responsible for doing forward/reverse DNS lookups -# -class DNSUtil - - - # - # Return the reverse DNS for the specified IP address, nil on failure. - # - def DNSUtil.ip_to_hostname( ip ) - resolved = nil - begin - timeout( 4 ) do - begin - Socket.getaddrinfo(ip, 'echo').each do |a| - resolved = a[2] if ( a ) - end - rescue SocketError - resolved = nil - end - end - rescue Timeout::Error => e - resolved = nil - end - resolved - end - - - # - # Convert a hostname to an IP address, return nil on failure. - # - def DNSUtil.hostname_to_ip( hostname ) - - resolved = nil - - begin - timeout( 4 ) do - begin - Socket.getaddrinfo(hostname, 'echo').each do |a| - resolved = a[3] if ( a ) - end - rescue SocketError - resolved = nil - end - end - rescue Timeout::Error => e - resolved = nil - end - resolved - end - -end - - -if __FILE__ == $0 then - - %w( ssh.steve.org.uk ipv6.steve.org.uk ).each do |name| - puts "Hostname test: #{name} #{DNSUtil.hostname_to_ip(name) }" - end - - %w( 80.68.85.46 80.68.85.48 2001:41c8:125:46::22 ).each do |name| - puts "Hostname test: #{name} #{DNSUtil.ip_to_hostname(name) }" - end -end -- cgit v1.2.1