class Wmap::Whois
Wrapper class of the 'ruby-whois' library
Attributes
timeout[RW]
verbose[RW]
Public Class Methods
new(params = {})
click to toggle source
Set default instance variables
# File lib/wmap/whois.rb, line 17 def initialize (params = {}) @verbose=params.fetch(:verbose, false) @timeout=params.fetch(:timeout, 10) end
Public Instance Methods
get_net_desc(ip)
click to toggle source
Method to extract the netname description from the whois data repository query for an IP
# File lib/wmap/whois.rb, line 51 def get_net_desc (ip) puts "Perform whois lookup on an IP address. Then extract the netname description from the query result for the IP: #{ip}" if @verbose begin ip.strip! raise "Unknown IP/CIDR format: #{ip}" unless is_ip?(ip) or is_cidr?(ip) desc=String.new content_to_parse=query(ip).to_s content_to_parse.scan(/^descr:(.+)\n/i).flatten.map do |entry| desc=desc + " " + entry.strip end if desc.empty? if content_to_parse =~ /^(.+)\((NET\-.+)\).+\n/i desc=$1.strip elsif content_to_parse =~ /^OrgName:(.+)\n/i desc=$1.strip else desc="UNKNOWN" end end return desc rescue Exception => ee puts "Exception on method get_net_desc: #{ee}" if @verbose return "UNKNOWN" end end
get_netname(ip)
click to toggle source
Method to extract the netname information from the whois data repository query for an IP
# File lib/wmap/whois.rb, line 30 def get_netname (ip) puts "Perform whois lookup on an IP address. Then extract the netname from the query result for the IP: #{ip}" if @verbose begin ip.strip! raise "Unknown IP/CIDR format: #{ip}" unless is_ip?(ip) or is_cidr?(ip) content_to_parse=query(ip).to_s if content_to_parse =~ /^netname:(.+)\n/i return $1.strip elsif content_to_parse =~ /^.+\((NET\-.+)\).+\n/i return $1.strip else return "UNKNOWN" end return "UNKNOWN" rescue Exception => ee puts "Exception on method get_netname: #{ee}" if @verbose return "UNKNOWN" end end