Whois function that searches RIR to return a response in a standard format
Ruby JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
config
data
doc
lib
log
pkg
test
README.rdoc
Rakefile
geany_run_script.bat
testgem.rb
testit.rb
vizi_whois-0.1.0.gem
vizi_whois-0.2.0.gem
vizi_whois-0.3.0.gem
vizi_whois-0.4.0.gem
vizi_whois.gemspec

README.rdoc

ViziWhois

Introduction

This gem module provides a classes to find the right Regional Internet Registry for a given IP Address. The query method will navigate each major RIR until a response is found.

Installation

Just run:

gem install vizi_whois

The following code will use a test file that contains a number of IP addresses to test the Gowhois method across a variety of RIRs.

Once the whois result is received it is passed to the Formatter method. This method extracts some of the most common fields from the results. The results from the various RIRs are presented in a common presentation format.

Usage

require 'vizi_whois'
require 'logger'
require 'socket'
syslog = Logger.new('./log/system.log',shift_age = 'weekly')
syslog.info "Starting IP address test file ... >>> "+Time.now.to_s
out_file = File.new('./log/output.log', 'w')
File.delete('./log/formatted.log') if File.exist?('./log/formatted.log') 
formatted_file = File.new('./log/formatted.log', 'w')
# Open test file for reading
File.open('./data/testfile.txt', 'r') do |file|
  rec_count = 0
  while(line = file.gets) # Read each line of the test file, one IP address per line
    @whoisresult = Vizi::Gowhois.new
    p line.chomp
    rarray = @whoisresult.query(line.chomp)
    @contents = rarray[0]
    out_file.puts '----------------------------------------------------------------'
    out_file.puts '> ' + line 
    out_file.puts '>> ' + rarray[1]
    out_file.puts '>>> ' + rarray[2]     
    out_file.puts '----------------------------------------------------------------'    
    out_file.puts @contents
    @result = Vizi::Formatter.new
    @formatted = @result.parse(@contents, rarray[1], rarray[2]) 
    p @formatted   
    rec_count = rec_count + 1 
  end
  syslog.info "Record count is "+rec_count.to_s
  syslog.info "Ending ... >>> "+Time.now.to_s
end

License

This code is made available under the MIT license.

All users of this code should read and follow the acceptable use policies for the following whois servers; ARIN, RIPE, APNIC, AFRINIC and LACNIC.