-
-
Save michenriksen/4002006 to your computer and use it in GitHub Desktop.
Loops until given domain is resolvable. Used to check when new domains are live.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'resolv' | |
require 'date' | |
unless @domain = ARGV.first | |
puts "DNS Checker\n\n" | |
puts "Performs a DNS lookup on a domain until it can be resolved.\n\n" | |
puts "USAGE:" | |
puts " ruby #{__FILE__} <domain> [<sleep>]\n\n" | |
puts "The optional sleep argument defines the amount of time to wait between each" | |
puts "lookup attempt. If not specified, it defaults to 60 seconds." | |
exit | |
end | |
@sleep = (ARGV[1] || 60).to_i | |
puts "[#{DateTime.now}] Started DNS check for #{@domain}..." | |
# Public: Attempt to lookup the domain | |
# | |
# Returns IP address if resolved or false | |
def attempt_lookup | |
Resolv.getaddress(@domain) | |
rescue Resolv::ResolvError | |
false | |
end | |
begin | |
until ip_address = attempt_lookup | |
print '.' | |
sleep @sleep | |
end | |
puts "[#{DateTime.now}] Success: #{@domain} is pointing at #{ip_address}!" | |
puts "[#{DateTime.now}] Done." | |
rescue => e | |
puts "[#{DateTime.now}] Error: #{e.class}" | |
puts "[#{DateTime.now}] Message: #{e.message}" | |
puts "[#{DateTime.now}] Canceled." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment