Class: Wmap::Whois
Overview
Wrapper class of the ‘ruby-whois’ library
Constant Summary
Constants included from Utils::UrlMagic
Utils::UrlMagic::Max_http_timeout, Utils::UrlMagic::User_agent
Constants included from Utils::DomainRoot
Utils::DomainRoot::File_ccsld, Utils::DomainRoot::File_cctld, Utils::DomainRoot::File_gtld, Utils::DomainRoot::File_tld
Instance Attribute Summary collapse
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#get_net_desc(ip) ⇒ Object
Method to extract the netname description from the whois data repository query for an IP.
-
#get_netname(ip) ⇒ Object
Method to extract the netname information from the whois data repository query for an IP.
-
#initialize(params = {}) ⇒ Whois
constructor
Set default instance variables.
-
#lookup(object) ⇒ Object
(also: #query)
Wrapper for the Ruby Whois client class.
Methods included from Utils
#cidr_2_ips, #file_2_hash, #file_2_list, #get_nameserver, #get_nameservers, #host_2_ip, #host_2_ips, #is_cidr?, #is_fqdn?, #is_ip?, #list_2_file, #reverse_dns_lookup, #sort_ips, #valid_dns_record?, #zone_transferable?
Methods included from Utils::Logger
Methods included from Utils::UrlMagic
#create_absolute_url_from_base, #create_absolute_url_from_context, #host_2_url, #is_site?, #is_ssl?, #is_url?, #landing_location, #make_absolute, #normalize_url, #open_page, #redirect_location, #response_code, #response_headers, #url_2_host, #url_2_path, #url_2_port, #url_2_site, #urls_on_same_domain?
Methods included from Utils::DomainRoot
#get_domain_root, #get_domain_root_by_ccsld, #get_domain_root_by_cctld, #get_domain_root_by_tlds, #get_sub_domain, #is_domain_root?, #print_ccsld, #print_cctld, #print_gtld
Constructor Details
#initialize(params = {}) ⇒ Whois
Set default instance variables
17 18 19 20 |
# File 'lib/wmap/whois.rb', line 17 def initialize (params = {}) @verbose=params.fetch(:verbose, false) @timeout=params.fetch(:timeout, 10) end |
Instance Attribute Details
#timeout ⇒ Object
Returns the value of attribute timeout.
14 15 16 |
# File 'lib/wmap/whois.rb', line 14 def timeout @timeout end |
#verbose ⇒ Object
Returns the value of attribute verbose.
14 15 16 |
# File 'lib/wmap/whois.rb', line 14 def verbose @verbose end |
Instance Method Details
#get_net_desc(ip) ⇒ Object
Method to extract the netname description from the whois data repository query for an IP
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# 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) ⇒ Object
Method to extract the netname information from the whois data repository query for an IP
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# 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 |
#lookup(object) ⇒ Object Also known as: query
Wrapper for the Ruby Whois client class
23 24 25 26 |
# File 'lib/wmap/whois.rb', line 23 def lookup(object) puts "Perform whois lookup on: #{object}" if @verbose return Whois.lookup(object) end |