lib/dnsbl/client.rb
# lookup performs the sending of DNS queries for the given items
# returns an array of DNSBLResult
lookup performs the sending of DNS queries for the given items
returns an array of DNSBLResult
lookup performs the sending of DNS queries for the given items returns an array of DNSBLResult
def lookup(item)
			items = item
			if item.is_a? String
				items = [item]
			end
			results = []
			items.each do |item|
				sent = 0
				@starttime = Time.now.to_f
				itemtype = (item =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) ? 'ip' : 'domain'
				@dnsbls.each do |name,config|
					next if config['disabled']
					next unless config['type'] == itemtype
					begin
						msg = _encode_query(item,itemtype,config['domain'],config['apikey'])
						@sockets[@socket_index].send(msg,0)
						@socket_index += 1
						@socket_index %= @sockets.length
						sent += 1
					rescue Exception => e
						puts e
						puts e.backtrace.join("\n")
					end
				end
				while sent > 0
					r,_,_ = IO.select(@sockets,nil,nil,1.5)
					break unless r
					r.each do |s|
						begin
							response = _decode_response(s.recv(4096))
							results += response
						rescue Exception => e
							puts e
							puts e.backtrace.join("\n")
						end
						sent -= 1
					end
				end
			end
			results
		end
def lookup ( item ) items = item if item . is_a? String items = [ item ] end results = [ ] items . each do | item | sent = 0 @starttime = Time . now . to_f itemtype = ( item =~ / ^ \d {1,3} \. \d {1,3} \. \d {1,3} \. \d {1,3}$ / ) ? 'ip' : 'domain' @dnsbls . each do | name , config | next if config [ 'disabled' ] next unless config [ 'type' ] == itemtype begin msg = _encode_query ( item , itemtype , config [ 'domain' ] , config [ 'apikey' ] ) @sockets [ @socket_index ] . send ( msg , 0 ) @socket_index += 1 @socket_index %= @sockets . length sent += 1 rescue Exception => e puts e puts e . backtrace . join ( "\n" ) end end while sent > 0 r , _ , _ = IO . select ( @sockets , nil , nil , 1.5 ) break unless r r . each do | s | begin response = _decode_response ( s . recv ( 4096 ) ) results += response rescue Exception => e puts e puts e . backtrace . join ( "\n" ) end sent -= 1 end end end results end
lookup performs the sending of DNS queries for the given items
returns an array of DNSBLResult
lookup performs the sending of DNS queries for the given items returns an array of DNSBLResult
# if item is an array, use it, otherwise make it one # place the results in the results array # for each ip or hostname # sent is used to determine when we have all the answers # record the start time # determine the type of query # for each dnsbl that supports our type, create the DNS query packet and send it # rotate across our configured name servers and increment sent # while we still expect answers # wait on the socket for maximally 1.5 seconds # if we time out, break out of the loop # for each reply, decode it and receive results, decrement the pending answers
item
<not_specific>