passivedns-client 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9bc0b0ff155e1b9570c05b45f22368b0cfa79a83
4
- data.tar.gz: 4b2d805d77a29ef052c0003a116c21224166254f
3
+ metadata.gz: d8943fdb2df184fb90081be44049edc69a35ac80
4
+ data.tar.gz: 409d45d5b94c4ab0c1d3d3e7caa57d2e192add8d
5
5
  SHA512:
6
- metadata.gz: 21dd2aefcc5074d626047c4cf4e798c33b9dc063199667b29a68614463b464e01f91fe72b285ecf2a3a752f8ef1f9a4082c1da797f6ed405950becefa32e5c55
7
- data.tar.gz: 39c7c7ae6f931634c58c588a9ce7113bdcd776becc587036e6a51261ba7d67008619b9cdf9da478674ba34cc46d255a965a9dc6dbaec83c9092e59daa95a2b49
6
+ metadata.gz: 0b4d1bee2454906a09b5af88a48a3792ad0e9bdb032512362c7803f66ee12352bbe9ccf36e476fe5a406498d89e413588d2778650151480bb01d66a8e295dec3
7
+ data.tar.gz: 086a9fdf306f2c67c8ff7ace94fa36e14d07a1d8631931d8d22c32c5b9295bcb79d20b433e3e074de3d1a7ed2e2c13930ec8305104b90c23dd9b3c88b0bbb0f3
@@ -88,7 +88,10 @@ module PassiveDNS #:nodoc: don't document this
88
88
  ######### FIX BLANKS FOR MX
89
89
 
90
90
  end
91
- res << PDNSResult.new(self.class.name,response_time,r[0],r[2],r[1])
91
+ query = r[0]
92
+ answer = r[2]
93
+ rrtype = r[1]
94
+ res << PDNSResult.new(self.class.name,response_time,query,answer,rrtype)
92
95
  end
93
96
  end
94
97
  res
@@ -95,9 +95,11 @@ module PassiveDNS #:nodoc: don't document this
95
95
  # need to remove the json_class tag or the parser will crap itself trying to find a class to align it to
96
96
  page.split(/\n/).each do |line|
97
97
  row = JSON.parse(line)
98
+ firstseen = Time.at(row['time_first'].to_i)
99
+ lastseen = Time.at(row['time_last'].to_i)
98
100
  res << PDNSResult.new(self.class.name,response_time,
99
101
  row['rrname'], row['rdata'], row['rrtype'], 0,
100
- row['time_first'], row['time_last'], row['count'])
102
+ firstseen, lastseen, row['count'])
101
103
  end
102
104
  res
103
105
  rescue Exception => e
@@ -82,27 +82,31 @@ module PassiveDNS #:nodoc: don't document this
82
82
  else
83
83
  recs
84
84
  end
85
+ end
85
86
 
86
- private
87
+ private
87
88
 
88
- # parses the response of 360.cn's JSON reply to generate an array of PDNSResult
89
- def parse_json(page,query,response_time=0)
90
- res = []
91
- # need to remove the json_class tag or the parser will crap itself trying to find a class to align it to
92
- data = JSON.parse(page)
93
- data.each do |row|
94
- time_first = (row["time_first"]) ? Time.at(row["time_first"].to_i) : nil
95
- time_last = (row["time_last"]) ? Time.at(row["time_last"].to_i) : nil
96
- count = row["count"] || 0
97
- res << PDNSResult.new(self.class.name, response_time, row["rrname"], row["rdata"], row["rrtype"], time_first, time_last, count)
98
- end
99
- res
100
- rescue Exception => e
101
- $stderr.puts "#{self.class.name} Exception: #{e}"
102
- raise e
103
- end
104
-
105
- end
89
+ # parses the response of 360.cn's JSON reply to generate an array of PDNSResult
90
+ def parse_json(page,query,response_time=0)
91
+ res = []
92
+ # need to remove the json_class tag or the parser will crap itself trying to find a class to align it to
93
+ data = JSON.parse(page)
94
+ data.each do |row|
95
+ time_first = (row["time_first"]) ? Time.at(row["time_first"].to_i) : nil
96
+ time_last = (row["time_last"]) ? Time.at(row["time_last"].to_i) : nil
97
+ count = row["count"] || 0
98
+ query = row["rrname"]
99
+ answers = row["rdata"].gsub(/;$/,'').split(/;/)
100
+ rrtype = row["rrtype"]
101
+ answers.each do |answer|
102
+ res << PDNSResult.new(self.class.name, response_time, query, answer, rrtype, time_first, time_last, count)
103
+ end
104
+ end
105
+ res
106
+ rescue Exception => e
107
+ $stderr.puts "#{self.class.name} Exception: #{e}"
108
+ raise e
109
+ end
106
110
  end
107
111
  end
108
112
  end
@@ -90,12 +90,21 @@ module PassiveDNS #:nodoc: don't document this
90
90
  rows = page.split(/\n/)
91
91
  rows.each do |row|
92
92
  record = JSON.parse(row)
93
- record['rdata'] = [record['rdata']] if record['rdata'].class == String
94
- record['rdata'].each do |rdata|
93
+ answers = record['rdata']
94
+ answers = [record['rdata']] if record['rdata'].class == String
95
+ query = record['rrname'].gsub!(/\.$/,'')
96
+ rrtype = record['rrtype']
97
+ firstseen = Time.at(record['time_first'].to_i)
98
+ lastseen = Time.at(record['time_last'].to_i)
99
+ count = record['count']
100
+
101
+ answers.each do |answer|
102
+ answer.gsub!(/\.$/,'')
95
103
  if record['time_first']
96
- res << PDNSResult.new(self.class.name,response_time,record['rrname'],rdata,record['rrtype'],0,Time.at(record['time_first'].to_i).utc.strftime("%Y-%m-%dT%H:%M:%SZ"),Time.at(record['time_last'].to_i).utc.strftime("%Y-%m-%dT%H:%M:%SZ"),record['count'])
104
+ res << PDNSResult.new(self.class.name,response_time,query,answer,rrtype,
105
+ 0,firstseen,lastseen,count)
97
106
  else
98
- res << PDNSResult.new(self.class.name,response_time,record['rrname'],rdata,record['rrtype'])
107
+ res << PDNSResult.new(self.class.name,response_time,query,answer,rrtype)
99
108
  end
100
109
  end
101
110
  end
@@ -83,7 +83,14 @@ module PassiveDNS #:nodoc: don't document this
83
83
  if data['result']
84
84
  data['result'].each do |row|
85
85
  if row['query']
86
- res << PDNSResult.new(self.class.name,response_time,row['query'],row['answer'],row['type'].upcase,row['ttl'],row['first'],row['last'])
86
+ query = row['query']
87
+ answer = row['answer']
88
+ rrtype = row['type'].upcase
89
+ tty = row['ttl'].to_i
90
+ firstseen = row['first']
91
+ lastseen = row['last']
92
+ res << PDNSResult.new(self.class.name,response_time,
93
+ query, answer, rrtype, ttl, firstseen, lastseen)
87
94
  end
88
95
  end
89
96
  end
@@ -84,8 +84,10 @@ module PassiveDNS #:nodoc: don't document this
84
84
  if data['results']
85
85
  query = data['results']['value']
86
86
  data['results']['resolutions'].each do |row|
87
- first_seen = row['firstSeen']
88
- last_seen = row['lastSeen']
87
+ #p row['firstSeen']
88
+ #p row['lastSeen']
89
+ first_seen = (row['firstSeen'] == "None") ? nil : Time.parse(row['firstSeen']+" +0000")
90
+ last_seen = (row['lastSeen'] == "None") ? nil : Time.parse(row['lastSeen']+" +0000")
89
91
  value = row['value']
90
92
  source = row['source'].join(",")
91
93
  res << PDNSResult.new(self.class.name+"/"+source,response_time,
@@ -3,7 +3,7 @@
3
3
  require 'net/http'
4
4
  require 'net/https'
5
5
  require 'openssl'
6
- #require 'pp'
6
+ require 'pp'
7
7
 
8
8
  module PassiveDNS #:nodoc: don't document this
9
9
  # The Provider module contains all the Passive DNS provider client code
@@ -103,19 +103,21 @@ module PassiveDNS #:nodoc: don't document this
103
103
 
104
104
  # parses the response of riskiq's JSON reply to generate an array of PDNSResult
105
105
  def parse_json(page,query,response_time=0)
106
- #pp page
107
106
  res = []
108
107
  # need to remove the json_class tag or the parser will crap itself trying to find a class to align it to
109
108
  data = JSON.parse(page)
109
+ #pp data
110
110
  if data['records']
111
111
  data['records'].each do |record|
112
- name = record['name']
112
+ name = record['name'].gsub!(/\.$/,'')
113
113
  type = record['rrtype']
114
- last_seen = record['lastSeen']
115
- first_seen = record['firstSeen']
114
+ last_seen = Time.parse(record['lastSeen'])
115
+ first_seen = Time.parse(record['firstSeen'])
116
+ count = record['count']
116
117
  record['data'].each do |datum|
118
+ datum.gsub!(/\.$/,'')
117
119
  res << PDNSResult.new(self.class.name,response_time,
118
- name, datum, type, 0, first_seen, last_seen)
120
+ name, datum, type, 0, first_seen, last_seen, count)
119
121
  end
120
122
  end
121
123
  end
@@ -86,29 +86,39 @@ module PassiveDNS #:nodoc: don't document this
86
86
  # translates the data structure derived from of tcpiputils's JSON reply
87
87
  def format_recs(reply_data, question, delta)
88
88
  recs = []
89
+ fieldname = nil
90
+ rrtype = nil
91
+ add_records = false
89
92
  reply_data.each do |key, data|
90
93
  case key
91
94
  when "ipv4"
92
- data.each do |rec|
93
- recs << PDNSResult.new(self.class.name, delta, question, rec["ip"], "A", nil, nil, rec["updatedate"], nil)
94
- end
95
+ fieldname = "ip"
96
+ rrtype = "A"
97
+ add_records = true
95
98
  when "ipv6"
96
- data.each do |rec|
97
- recs << PDNSResult.new(self.class.name, delta, question, rec["ip"], "AAAA", nil, nil, rec["updatedate"], nil)
98
- end
99
+ fieldname = "ip"
100
+ rrtype = "AAAA"
101
+ add_records = true
99
102
  when "dns"
100
- data.each do |rec|
101
- recs << PDNSResult.new(self.class.name, delta, question, rec["dns"], "NS", nil, nil, rec["updatedate"], nil)
102
- end
103
+ fieldname = "dns"
104
+ rrtype = "NS"
105
+ add_records = true
103
106
  when "mx"
104
- data.each do |rec|
105
- recs << PDNSResult.new(self.class.name, delta, question, rec["dns"], "MX", nil, nil, rec["updatedate"], nil)
106
- end
107
+ fieldname = "dns"
108
+ rrtype = "MX"
109
+ add_records = true
107
110
  when "domains"
108
111
  data.each do |rec|
112
+ lastseen = (rec["updatedate"]) ? Date.parse(rec["updatedate"]) : nil
109
113
  recs << PDNSResult.new(self.class.name, delta, rec, question, "A", nil, nil, nil, nil)
110
114
  end
111
115
  end
116
+ if add_records
117
+ data.each do |rec|
118
+ lastseen = (rec["updatedate"]) ? Date.parse(rec["updatedate"]) : nil
119
+ recs << PDNSResult.new(self.class.name, delta, question, rec[fieldname], rrtype, nil, nil, lastseen, nil)
120
+ end
121
+ end
112
122
  end
113
123
  recs
114
124
  end
@@ -87,10 +87,11 @@ module PassiveDNS #:nodoc: don't document this
87
87
  data = JSON.parse(page)
88
88
  if data['resolutions']
89
89
  data['resolutions'].each do |row|
90
+ lastseen = Time.parse(row['last_resolved']+" +0000")
90
91
  if row['ip_address']
91
- res << PDNSResult.new(self.class.name,response_time,query,row['ip_address'],'A',nil,nil,row['last_resolved'])
92
+ res << PDNSResult.new(self.class.name,response_time,query,row['ip_address'],'A',nil,nil,lastseen)
92
93
  elsif row['hostname']
93
- res << PDNSResult.new(self.class.name,response_time,row['hostname'],query,'A',nil,nil,row['last_resolved'])
94
+ res << PDNSResult.new(self.class.name,response_time,row['hostname'],query,'A',nil,nil,lastseen)
94
95
  end
95
96
  end
96
97
  end
@@ -2,6 +2,6 @@ module PassiveDNS # :nodoc:
2
2
  # coodinates the lookups accross all configured PassiveDNS providers
3
3
  class Client
4
4
  # version of PassiveDNS::Client
5
- VERSION = "2.1.0"
5
+ VERSION = "2.1.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passivedns-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - chrislee35
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-07 00:00:00.000000000 Z
11
+ date: 2015-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json