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__), "./url_creator.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")
module Peertracker
class ASInfo
def set_as_info_for_ip(ip_address)
request = HTTPRequest.new(URLCreator.new("ip.searchwww.com", ip_address).create_url)
ASParser.new.parse_response(request.perform_request)
raw_code = WhoisRequest.new.get_as_info(ip_address)
raw_country = WhoisRequest.new.get_country_info(ip_address)
ASParser.new.parse_response(raw_code, raw_country)
end
class << self

View File

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