Class: DoroParser::DoroDNS

Inherits:
Object
  • Object
show all
Defined in:
lib/dorothy2/DEM.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(c) ⇒ DoroDNS

Returns a new instance of DoroDNS.



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/dorothy2/DEM.rb', line 261

def initialize(c)
  @dns = Net::DNS::Packet::parse(c)
  if qry? #is a query
    q = @dns.question.first
    @cls_i = q.qClass     #Net::DNS::Question.parse(c[12..offset]).qClass
    @name = q.qName
    @type_i = q.qType
    @ttl = 'null'
    @address = 'null'
    @data = 'null'
    
    elsif !@dns.answer.empty? #contain an asnwer
    #TODO only the first answer is parsed
    a = @dns.answer.each.first
    @ttl = a.ttl
    @name = a.name
    
      @type = a.type
    @type_i = Net::DNS::RR::Types.new @type
    
    
    @cls = a.cls
    @cls_i = Net::DNS::RR::Classes.new @cls   
    
    
    case @type 
      
      when "A"
      @address = @dns.answer.each.first.address  
      @data = 'null'
      
      when "AAAA"
      @address = @dns.answer.each.first.address  
      @data = 'null'
      
      when "MX" then
      
      @data = @dns.answer.each.first.exchange 
      @address = 'null'
      
      when "CNAME" then
      
      @data = @dns.answer.each.first.cname
      @address = 'null'
      
      else 
      
      @address = 'null'
      @data = 'null'
      
    end
  end
  
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



258
259
260
# File 'lib/dorothy2/DEM.rb', line 258

def address
  @address
end

#clsObject

Returns the value of attribute cls.



256
257
258
# File 'lib/dorothy2/DEM.rb', line 256

def cls
  @cls
end

#cls_iObject

Returns the value of attribute cls_i.



257
258
259
# File 'lib/dorothy2/DEM.rb', line 257

def cls_i
  @cls_i
end

#dataObject

Returns the value of attribute data.



259
260
261
# File 'lib/dorothy2/DEM.rb', line 259

def data
  @data
end

#dnsObject

Returns the value of attribute dns.



251
252
253
# File 'lib/dorothy2/DEM.rb', line 251

def dns
  @dns
end

#nameObject

Returns the value of attribute name.



253
254
255
# File 'lib/dorothy2/DEM.rb', line 253

def name
  @name
end

#ttlObject

Returns the value of attribute ttl.



252
253
254
# File 'lib/dorothy2/DEM.rb', line 252

def ttl
  @ttl
end

#typeObject

Returns the value of attribute type.



254
255
256
# File 'lib/dorothy2/DEM.rb', line 254

def type
  @type
end

#type_iObject

Returns the value of attribute type_i.



255
256
257
# File 'lib/dorothy2/DEM.rb', line 255

def type_i
  @type_i
end

Instance Method Details

#qry?Boolean

Returns:

  • (Boolean)


317
318
319
# File 'lib/dorothy2/DEM.rb', line 317

def qry?
  @dns.answer.empty?
end