class TeamCymru::ASNClient
Public Class Methods
new(server='whois.cymru.com', port=43)
click to toggle source
# File lib/teamcymru/asnclient.rb, line 30 def initialize(server='whois.cymru.com', port=43) @server = server @port = port @cache = Cache.new(nil,nil,10000,24*60*60) end
Public Instance Methods
lookup(iplines)
click to toggle source
# File lib/teamcymru/asnclient.rb, line 36 def lookup(iplines) t = TCPSocket.new(@server,@port) t.puts("begin") t.puts("verbose") t.readline oneshot = false if iplines.class == String iplines = [iplines] oneshot = true end recs = [] iplines.each do |ipdata| ip,data = ipdata.split(/ /,2) rec = nil @cache.each_key do |cidr| if cidr.include?(ip) rec = @cache[cidr] rec.ip = ip rec.data = data rec.cached = true break end end unless rec t.puts(ipdata) t.flush l = t.readline rec = ASNRecord.from_s(l) cidr = IPAddr.new(rec.cidr) if rec.cidr != '' if cidr @cache[cidr] = rec end end recs << rec end t.puts("end") t.close return recs[0] if oneshot recs end