From: John Dong Date: Fri, 31 Aug 2007 15:43:41 +0000 (-0400) Subject: Hack WHOIS lib to implement a 5-second timeout on DNS resolution. X-Git-Url: https://projects.mako.cc/source/selectricity-live/commitdiff_plain/ce1489ae318bfe129070ecaf4e5c422015572caf?hp=-c Hack WHOIS lib to implement a 5-second timeout on DNS resolution. --- ce1489ae318bfe129070ecaf4e5c422015572caf diff --git a/app/views/quickvote/list_voters.rhtml b/app/views/quickvote/list_voters.rhtml index 695794f..be11290 100644 --- a/app/views/quickvote/list_voters.rhtml +++ b/app/views/quickvote/list_voters.rhtml @@ -1,5 +1,5 @@ <%= GMap.header %> - +<%require('whois/whois') %>
Quickvote Voters @@ -31,13 +31,13 @@ if Cache and w=Cache.get("WHOIS:#{voter.ipaddress}") elsif Cache puts "CREATE" - w= Whois::Whois.new(IPAddr.new(voter.ipaddress),false) + w= Whois::Whois.new(IPAddr.new(voter.ipaddress),true) puts "SEARCH" w.search_whois puts "DONE" Cache.set("WHOIS:#{voter.ipaddress}", w) else - w= Whois::Whois.new(IPAddr.new(voter.ipaddress),false) + w= Whois::Whois.new(IPAddr.new(voter.ipaddress),true) w.search_whois end @@ -45,7 +45,12 @@ <%=h((w.host == nil or w.host.empty?) ? voter.ipaddress : w.host)%> - <%=h (w.all.grep(/^(OrgName|org-name)/)[0] or "").sub(/^(OrgName|org-name)\:/,'').strip -%> - <%= (w.all.grep(/^(NetName|netname)/)[0] or "").sub(/^(NetName|netname)\:/,'').strip %> + <%org=(w.all.grep(/^(OrgName|org-name)/)[0] or "").sub(/^(OrgName|org-name)\:/,'').strip+" - "+ (w.all.grep(/^(NetName|netname)/)[0] or "").sub(/^(NetName|netname)\:/,'').strip %> + <% if org =~ /IANA/ %> + <%= "No additional information" %> + <% else %> + <%= h(org) %> + <% end %> <% rescue ArgumentError => err %> <%=h err %> diff --git a/lib/whois/whois.rb b/lib/whois/whois.rb index 88c735b..7cc6e9d 100755 --- a/lib/whois/whois.rb +++ b/lib/whois/whois.rb @@ -4,6 +4,8 @@ require 'socket' require 'resolv' require 'ipaddr' require 'yaml' +require 'timeout' + require File.dirname(__FILE__) + '/server/server' # Module for manage all Whois Class @@ -92,7 +94,11 @@ module Whois def search_host begin if @host_search - @host = Resolv.getname self.ip.to_s + begin + timeout(5) {@host = Resolv.getname self.ip.to_s} + rescue Timeout::Error + @host=nil + end else @host = nil end