summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/iplookup.rb
diff options
context:
space:
mode:
authorRyan Waldron <rwaldron@github.com>2013-04-18 16:59:22 -0500
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2013-04-25 07:18:55 +0200
commitd9ca58e7f41e4a27e087cae4cf6fe8e69aa02c73 (patch)
tree9cf0f91cad50454bcf04aeb2953133e67a3693b5 /data/rbot/plugins/iplookup.rb
parenta859a2efbad135fd2f2106618195604691489f0e (diff)
Fix parsing whois results so that we can get valid results for at least a great many queries
Diffstat (limited to 'data/rbot/plugins/iplookup.rb')
-rw-r--r--data/rbot/plugins/iplookup.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/data/rbot/plugins/iplookup.rb b/data/rbot/plugins/iplookup.rb
index 5277b95f..e629d233 100644
--- a/data/rbot/plugins/iplookup.rb
+++ b/data/rbot/plugins/iplookup.rb
@@ -100,7 +100,7 @@ module ArinWhois
def parse_chunks
return if @data =~ /^No match found /
chunks = @data.gsub(/^# ARIN WHOIS database, last updated.+/m, '').scan(/(([^\n]+\n)+\n)/m)
- chunks.map do |chunk|
+ chunks = chunks.map do |chunk|
result = Chunk.new
chunk[0].scan(/([A-Za-z]+?):(.*)/).each do |tuple|
@@ -110,6 +110,7 @@ module ArinWhois
result
end
+ chunks.reject(&:empty?)
end
@@ -131,9 +132,12 @@ module ArinWhois
return unless datas = get_parsed_data
datas_with_bitmasks = datas.map do |data|
- bitmask = data[:net]['CIDR'].split('/')[1].to_i
+ next unless data[:customer]
+ next unless net_data = data[:net]
+ bitmask = net_data['CIDR'].split('/')[1].to_i
[bitmask, data]
end
+ datas_with_bitmasks.compact!
#datas_with_bitmasks.sort.each{|x|puts x[0]}
winner = datas_with_bitmasks.sort[-1][1]
end
@@ -147,11 +151,11 @@ module_function
s.write(query_string+"\n")
ret = s.read
s.close
- return ret
+ ret
end
def lookup(ip)
- data = raw_whois("+#{ip}", 'whois.arin.net')
+ data = raw_whois("+ n #{ip}", 'whois.arin.net')
arin = ArinWhoisParser.new data
arin.get_most_specific_owner
end