changes as fetcher to use WHOIS db

This commit is contained in:
Mateusz Zawisza 2012-08-25 21:50:35 +02:00 committed by Johannes Dewender
parent 0259b8bf30
commit 50cf589d75
3 changed files with 21 additions and 8 deletions

View File

@ -3,13 +3,15 @@ require File.join(File.dirname(__FILE__), "../config/database.rb")
require File.join(File.dirname(__FILE__), "./model/peer.rb") require File.join(File.dirname(__FILE__), "./model/peer.rb")
require File.join(File.dirname(__FILE__), "./url_creator.rb") require File.join(File.dirname(__FILE__), "./url_creator.rb")
require File.join(File.dirname(__FILE__), "./http_request.rb") require File.join(File.dirname(__FILE__), "./http_request.rb")
require File.join(File.dirname(__FILE__), "./whois_request.rb")
require File.join(File.dirname(__FILE__), "./as_parser.rb") require File.join(File.dirname(__FILE__), "./as_parser.rb")
module Peertracker module Peertracker
class ASInfo class ASInfo
def set_as_info_for_ip(ip_address) def set_as_info_for_ip(ip_address)
request = HTTPRequest.new(URLCreator.new("ip.searchwww.com", ip_address).create_url) raw_code = WhoisRequest.new.get_as_info(ip_address)
ASParser.new.parse_response(request.perform_request) raw_country = WhoisRequest.new.get_country_info(ip_address)
ASParser.new.parse_response(raw_code, raw_country)
end end
class << self class << self

View File

@ -1,20 +1,20 @@
class ASParser class ASParser
def parse_response(response) def parse_response(raw_code, raw_country)
[parse_as(response),parse_country(response)] [parse_as(raw_code),parse_country(raw_country)]
end end
def parse_as(response) def parse_as(raw_code)
begin begin
response.scan(/Provider:<\/b><p>(\w*)/)[0][0] raw_code.scan(/origin:\s*([A-Z0-9]*)\s/i)[0][0]
rescue => e rescue => e
puts "Could not parse AS" puts "Could not parse AS"
nil nil
end end
end end
def parse_country(response) def parse_country(raw_country)
begin begin
response.scan(/Location:<\/b><p>(.*)<p>/)[0][0].split(",").last.strip raw_country.scan(/country:\s*([A-Z0-9]*)\s/i)[0][0]
rescue => e rescue => e
puts "Could not parse Country" puts "Could not parse Country"
nil nil

11
ruby/lib/whois_request.rb Normal file
View File

@ -0,0 +1,11 @@
module Peertracker
class WhoisRequest
def get_as_info(ip_address)
`whois -m #{ip_address}`
end
def get_country_info(ip_address)
`whois -l #{ip_address}`
end
end
end