Module: NicInfo

Defined in:
lib/nicinfo/enum.rb,
lib/nicinfo/ip.rb,
lib/nicinfo/ns.rb,
lib/nicinfo/cache.rb,
lib/nicinfo/utils.rb,
lib/nicinfo/autnum.rb,
lib/nicinfo/config.rb,
lib/nicinfo/domain.rb,
lib/nicinfo/entity.rb,
lib/nicinfo/ds_data.rb,
lib/nicinfo/factory.rb,
lib/nicinfo/notices.rb,
lib/nicinfo/key_data.rb,
lib/nicinfo/bootstrap.rb,
lib/nicinfo/constants.rb,
lib/nicinfo/data_tree.rb,
lib/nicinfo/error_code.rb,
lib/nicinfo/traceroute.rb,
lib/nicinfo/common_json.rb,
lib/nicinfo/common_names.rb,
lib/nicinfo/nicinfo_main.rb,
lib/nicinfo/nicinfo_logger.rb

Overview

IPv4 and IPv6 regular expressions are credited to Mike Poulson and are found here:

http://blogs.msdn.com/b/mpoulson/archive/2005/01/10/350037.aspx

Defined Under Namespace

Classes: Adr, AttentionType, Autnum, Bootstrap, Cache, ColorScheme, CommonJson, Config, DataAmount, DataNode, DataTree, Domain, DsData, Email, Entity, Enum, ErrorCode, EventActor, Factory, Ip, JCard, JcrMode, KeyData, Logger, Main, MessageLevel, MyHTTPResponse, Notices, Ns, Org, QueryType, ResponseObjSet, Tel

Constant Summary collapse

VERSION =
"1.5.2"
VERSION_LABEL =
"NicInfo v." + VERSION
"Copyright (c) 2011-2017 American Registry for Internet Numbers (ARIN)"
CONFIG_VERSION =
4
NET_HANDLE_REGEX =

regular expressions

/^NET-.*/i
NET6_HANDLE_REGEX =
/^NET6-.*/i
AS_REGEX =
/^[0-9]{1,10}$/
ASN_REGEX =
/^AS[0-9]{1,20}$/i
IP4_ARPA =
/\.in-addr\.arpa[\.]?/i
IP6_ARPA =
/\.ip6\.arpa[\.]?/i
DATA_TREE_ADDR_REGEX =
/\d=$/
DOMAIN_REGEX =
/^([\S\-]+\.?)+\.([a-z][a-z0\-]+)\.?$/i
DOMAIN_SRCH_REGEX =
/^([\S\-]+\.?)+\.([a-z][a-z0\-\*]+)\.?$/i
NS_REGEX =
/^ns[0-9]\.([\S\-]+\.?)+\.([a-z][a-z0\-]+)\.?$/i
URL_REGEX =
/^(http|https):\/\/.*/
ENTITY_REGEX =
/^.*\-.*/
IPV4_REGEX =

IPv4 and IPv6 regular expressions are credited to Mike Poulson and are found here:

http://blogs.msdn.com/b/mpoulson/archive/2005/01/10/350037.aspx
/\A(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\z/
IPV6_REGEX =
/\A(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\z/
IPV6_HEXCOMPRESS_REGEX =
/\A((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)\z/
LASTTREE_YAML =

File Name Constants

"lasttree.yaml"
DEMO_DIR =
"demo"
BOOTSTRAP_FILE_DIR =
"bsfiles"
ASN_BOOTSTRAP =
"asn.json"
DNS_BOOTSTRAP =
"dns.json"
ENTITY_BOOTSTRAP =
"entity.json"
IPV4_BOOTSTRAP =
"ipv4.json"
IPV6_BOOTSTRAP =
"ipv6.json"
JCR_DIR =

JCR Constants

"jcr"
RDAP_JCR =
"rdap.jcr"
STRICT_RDAP_JCR =
"strict.jcr"
JCR_ROOT_ENTITY =
"entity_response"
JCR_ROOT_NAMESERVER =
"nameserver_response"
JCR_ROOT_DOMAIN =
"domain_response"
JCR_ROOT_NETWORK =
"network_response"
JCR_ROOT_AUTNUM =
"autnum_response"
JCR_ROOT_ERROR =
"error_response"
JCR_ROOT_HELP =
"help_response"
JCR_ROOT_DOMAIN_SEARCH =
"domainSearch_response"
JCR_ROOT_NAMESERVER_SEARCH =
"nameserverSearch_response"
JCR_ROOT_ENTITY_SEARCH =
"entitySearch_response"
OUTPUT =

Config constants

"output"
MESSAGES =
"messages"
MESSAGES_FILE =
"messages_file"
DATA =
"data"
DATA_FILE =
"data_file"
PAGER =
"pager"
AUTO_WRAP =
"auto_wrap"
DETECT_WIDTH =
"detect_width"
DEFAULT_WIDTH =
"default_width"
COLOR_SCHEME =
"color_scheme"
CACHE =
"cache"
CACHE_EXPIRY =
"cache_expiry"
CACHE_EVICTION =
"cache_eviction"
USE_CACHE =
"use_cache"
CLEAN_CACHE =
"clean_cache"
BOOTSTRAP =
"bootstrap"
BOOTSTRAP_URL =
"bootstrap_url"
HELP_ROOT_URL =
"help_root_url"
ENTITY_ROOT_URL =
"entity_root_url"
IP_ROOT_URL =
"ip_root_url"
AS_ROOT_URL =
"as_root_url"
DOMAIN_ROOT_URL =
"domain_root_url"
CHECK_BSFILES_AGE =
"check_bsfiles_age"
BSFILES_AGE =
"bsfiles_age"
UPDATE_BSFILES =
"update_bsfiles"
SEARCH =
"search"
SUBSTRING =
"substring"
CONFIG =
"config"
VERSION_CONFIG =
"version"
SECURITY =
"security"
TRY_INSECURE =
"try_insecure"
NICINFO_DEMO_URL =

NicInfo values

"nicInfo_demoUrl"
NICINFO_DEMO_HINT =
"nicInfo_demoHint"
NICINFO_DEMO_ERROR =
"nicInfo_demoError"
RDAP_CONTENT_TYPE =

Other constants

"application/rdap+json"
JSON_CONTENT_TYPE =
"application/json"
DNSSEC_ALGORITHMS =
{
     0 =>  "reserved",
     1 =>  "RSA/MD5",
     2 =>  "Diffie-Hellman",
     3 =>  "DSA/SHA-1",
     4 =>  "Elliptic Curve",
     5 =>  "RSA/SHA-1",
   252 =>  "Indirect",
   253 =>  "Private DNS",
   254 =>  "Private OID",
   255 =>  "reserved"
}
BSFILE_LAST_CHECK_FILENAME =
"_last_check_time.txt"
EXTENDED_HELP =
<<EXTENDED_HELP

QUERIES
  For most query values, the query type is inferred. However, some types of queries
  cannot be inferred and so the -t parameter must be used. The domain search by name
  (dsbyname) and entity search by name (esbyname) queries can take wildcards ('*'),
  but these must be quoted or escaped to avoid processing by the invoking OS shell
  on Unix-like operating systems.

CONFIGURATION
  When this program is run for the first time, it creates a directory called .NicInfo
  (on Unix style platforms) or NicInfo (on Windows) in the users home directory. The
  home directory is determined by the $HOME environment variable on Unix style platforms
  and $APPDATA on Windows.

  A configuration file is created in this directory called config.yaml. This is a YAML
  file and contains a means for specifying most of the features of this program (instead
  of needing to specify them on the command line as options). To set the configuration
  back to the installation defaults, use the --reset option. This maybe desirable when
  updating versions of this program.

  A directory called rdap_cache is also created inside this directory. It holds cached
  values from previously executed queries.

CACHING
  This program will write query responses to a cache. By default, answers are pulled
  from the cache if present. This can be turned on or off with the --cache parameter or
  using the cache/use_cache value in the configuration file.

  Expiration of items in the cache and eviction of items from the cache can also be
  controlled. The cache can be manually emptied using the --empty-cache parameter.

BOOTSTRAPPING
  Bootstrapping is the process of finding an appropriate RDAP server in which to send
  queries. This program has a three tier bootstrapping process.

  The first tier looks up the most appropriate server using internal tables compiled
  from IANA registries. If an appropriate server cannot be found, bootstrapping falls
  to the second tier.

  The second tier has a default server for each type of RDAP query (domain, ip, autnum,
  nameserver, and entity). If this program cannot determine the type of query, bootstrapping
  falls to the third tier.

  The third tier is a default server for all queries.

  All bootstrap URLs are specified in the configuration file. Bootstrapping maybe
  bypassed using the -b or --base option (or by setting the bootstrap/base_url in the
  configuration file).

USAGE FOR SCRIPTING
  For usage with shell scripting, there are a couple of useful command line parameters.

  The --json parameter suppresses the human-readable output and instead emits the JSON
  returned by the server. When not writing to an output file, this options should be
  used with the -Q option to suppress the pager and program runtime messages so that
  the JSON maybe run through a JSON parser.

  The --jv parameter instructs this program to parse the JSON and emit specific JSON
  values.  This parameter is also useful in combination with the -Q option to feed the
  JSON values into other programs.  The syntax for specifying a JSON value is a
  list of JSON object member names or integers signifying JSON array indexes separated
  by a period, such as name1.name2.3.name4.5. For example, "entities.0.handle" would
  be useful for getting at the "handle" value from the following JSON:

    { "entities" : [ { "handle": "foo" } ] }

  Multiple --jv parameters may be specified.

DEMONSTRATION QUERIES
  There are several built-in demonstration queries that may be exercised to show the
  utility of RDAP. To use these queries, the --demo parameter must be used to populate
  the query answers into the cache. If the cache is already populated with items, it
  may be necessary to clean the cache using the --empty-cache parameter.

  When the --demo parameter is given, the list of demonstration queries will be printed
  out.

RDAP VALIDATION
  This program has built-in checks for verifying the validity of RDAP responses.
  Beyond these normal built-in checks, it can also JSON Content Rules to check
  the validity of the responses using the --jcr parameter, which requires either
  the standard (i.e. --jcr standard) or strict (i.e. --jcr strict) parameter
  options.

MORE INFORMATION
  More information about this program may be found at 
  https://github.com/arineng/nicinfo/wiki
EXTENDED_HELP

Class Method Summary collapse

Class Method Details

.add_entity_nodes(entities, node) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/nicinfo/common_json.rb', line 44

def NicInfo.add_entity_nodes entities, node
  entities.each do |entity|
    entity_node = entity.to_node
    node.add_child( entity_node )
    NicInfo::add_entity_nodes( entity.entities, entity_node )
  end if entities
end

.add_entity_respobjs(entities, respobjs) ⇒ Object



52
53
54
55
56
57
# File 'lib/nicinfo/common_json.rb', line 52

def NicInfo.add_entity_respobjs entities, respobjs
  entities.each do |entity|
    respobjs.add( entity )
    NicInfo::add_entity_respobjs( entity.entities, respobjs )
  end if entities
end

.capitalize(str) ⇒ Object



188
189
190
191
192
193
194
# File 'lib/nicinfo/utils.rb', line 188

def NicInfo.capitalize str
  words = str.split( /\s/ )
  words.each do |word|
    word.capitalize!
  end
  return words.join( " " )
end

.display_autnum(json_data, config, data_tree) ⇒ Object



24
25
26
27
# File 'lib/nicinfo/autnum.rb', line 24

def NicInfo.display_autnum json_data, config, data_tree
  autnum = config.factory.new_autnum.process( json_data )
  NicInfo::display_object_with_entities( autnum, config, data_tree )
end

.display_domain(json_data, config, data_node) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
76
77
78
79
80
# File 'lib/nicinfo/domain.rb', line 27

def NicInfo.display_domain json_data, config, data_node
  obj_array = json_data
  unless json_data.instance_of? Array
    obj_array = Array.new
    obj_array << json_data
  end
  respObjs = ResponseObjSet.new config
  obj_array.each do |array_object|
    domain = config.factory.new_domain.process( array_object )
    root = domain.to_node
    data_node.add_root( root )
    if !domain.entities.empty? or !domain.nameservers.empty?
      domain.ds_data_objs.each do |ds|
        ds_node = ds.to_node
        root.add_child( ds_node )
      end
      domain.key_data_objs.each do |key|
        key_node = key.to_node
        root.add_child( key_node )
      end
      NicInfo::add_entity_nodes( domain.entities, root )
      domain.nameservers.each do |ns|
        ns_node = ns.to_node
        root.add_child( ns_node )
        NicInfo::add_entity_nodes( ns.entities, ns_node )
      end
    end
    if domain.network
      net_node = domain.network.to_node
      root.add_child net_node
      NicInfo::add_entity_nodes( domain.network.entities, net_node )
    end
    respObjs.add domain
    domain.ds_data_objs.each do |ds|
      respObjs.add ds
    end
    domain.key_data_objs.each do |key|
      respObjs.add key
    end
    NicInfo::add_entity_respobjs( domain.entities, respObjs )
    respObjs.associateEntities domain.entities
    domain.nameservers.each do |ns|
      respObjs.add ns
      NicInfo::add_entity_respobjs( ns.entities, respObjs )
      respObjs.associateEntities ns.entities
    end
    if domain.network
      respObjs.add domain.network
      NicInfo::add_entity_respobjs( domain.network.entities, respObjs )
    end
  end
  data_node.to_normal_log( config.logger, true )
  respObjs.display
end

.display_domains(json_data, config, data_tree) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/nicinfo/domain.rb', line 82

def NicInfo.display_domains json_data, config, data_tree
  domain_array = json_data[ "domainSearchResults" ]
  if domain_array != nil
    if domain_array.instance_of? Array
      NicInfo.display_domain( domain_array, config, data_tree )
    else
      config.conf_msgs << "'domainSearchResults' is not an array"
    end
  else
    config.conf_msgs << "'domainSearchResults' is not present"
  end
end

.display_ds_data(json_data, config, data_node) ⇒ Object



23
24
25
# File 'lib/nicinfo/ds_data.rb', line 23

def NicInfo.display_ds_data json_data, config, data_node
  ds_data = DsData.new( config ).process( json_data ).display
end

.display_entities(json_data, config, data_tree) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/nicinfo/entity.rb', line 61

def NicInfo.display_entities json_data, config, data_tree
  entity_array = json_data[ "entitySearchResults" ]
  if entity_array != nil
    if entity_array.instance_of? Array
      display_array = Array.new
      entity_array.each do |ea|
        entity = config.factory.new_entity.process( ea )
        display_array << entity
      end
      NicInfo.display_object_with_entities( display_array, config, data_tree )
    else
      config.conf_msgs << "'entitySearchResults' is not an array"
    end
  else
    config.conf_msgs << "'entitySearchResults' is not present"
  end
end

.display_entity(json_data, config, data_tree) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/nicinfo/entity.rb', line 23

def NicInfo.display_entity json_data, config, data_tree
  entity = config.factory.new_entity.process( json_data )

  respobjs = ResponseObjSet.new config
  root = entity.to_node
  data_tree.add_root( root )
  if !entity.entities.empty?
    NicInfo::add_entity_nodes( entity.entities, root )
  end
  entity.networks.each do |network|
    net_node = network.to_node
    root.add_child( net_node )
    NicInfo::add_entity_nodes( network.entities, net_node )
  end
  entity.autnums.each do |autnum|
    as_node = autnum.to_node
    root.add_child( as_node )
    NicInfo::add_entity_nodes( autnum.entities, as_node )
  end

  respobjs.add entity
  NicInfo::add_entity_respobjs( entity.entities, respobjs )
  respobjs.associateEntities entity.entities
  entity.networks.each do |network|
    respobjs.add network
    NicInfo::add_entity_respobjs( network.entities, respobjs )
    respobjs.associateEntities network.entities
  end
  entity.autnums.each do |autnum|
    respobjs.add autnum
    NicInfo::add_entity_respobjs( autnum.entities, respobjs )
    respobjs.associateEntities autnum.entities
  end

  data_tree.to_normal_log( config.logger, true )
  respobjs.display
end

.display_ip(json_data, config, data_tree) ⇒ Object



27
28
29
30
# File 'lib/nicinfo/ip.rb', line 27

def NicInfo.display_ip json_data, config, data_tree
  ip = config.factory.new_ip.process( json_data )
  NicInfo::display_object_with_entities( ip, config, data_tree )
end

.display_key_data(json_data, config, data_node) ⇒ Object



23
24
25
# File 'lib/nicinfo/key_data.rb', line 23

def NicInfo.display_key_data json_data, config, data_node
  key_data = KeyData.new( config ).process( json_data ).display
end

.display_nameservers(json_data, config, data_node) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/nicinfo/ns.rb', line 29

def NicInfo.display_nameservers json_data, config, data_node
  ns_array = json_data[ "nameserverSearchResults" ]
  if ns_array != nil
    if ns_array.instance_of? Array
      display_array = Array.new
      ns_array.each do |ea|
        ns = config.factory.new_ns.process( ea )
        display_array << ns
      end
      NicInfo::display_object_with_entities( display_array, config, data_node )
    else
      config.conf_msgs << "'nameserverSearchResults' is not an array"
    end
  else
    config.conf_msgs << "'nameserverSearchResults' is not present"
  end
end

.display_ns(json_data, config, data_node) ⇒ Object



24
25
26
27
# File 'lib/nicinfo/ns.rb', line 24

def NicInfo.display_ns json_data, config, data_node
  ns = config.factory.new_ns.process( json_data )
  NicInfo::display_object_with_entities( ns, config, data_node )
end

.display_object_with_entities(object, config, data_node) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/nicinfo/common_json.rb', line 23

def NicInfo.display_object_with_entities object, config, data_node
  obj_array = object
  unless object.instance_of? Array
    obj_array = Array.new
    obj_array << object
  end
  respobjs = ResponseObjSet.new config
  obj_array.each do |array_object|
    root = array_object.to_node
    data_node.add_root( root )
    if !array_object.entities.empty?
      NicInfo::add_entity_nodes( array_object.entities, root )
    end
    respobjs.add array_object
    NicInfo::add_entity_respobjs( array_object.entities, respobjs )
    respobjs.associateEntities array_object.entities
  end
  data_node.to_normal_log( config.logger, true )
  respobjs.display
end


170
171
172
# File 'lib/nicinfo/utils.rb', line 170

def NicInfo.get_about_link links
  get_link "about", links
end

.get_algorithm(json_data) ⇒ Object



51
52
53
# File 'lib/nicinfo/utils.rb', line 51

def NicInfo.get_algorithm json_data
  return json_data[ "algorithm" ]
end


154
155
156
# File 'lib/nicinfo/utils.rb', line 154

def NicInfo.get_alternate_link links
  get_link "alternate", links
end

.get_autnums(json_data) ⇒ Object



104
105
106
# File 'lib/nicinfo/utils.rb', line 104

def NicInfo.get_autnums json_data
  return json_data[ "autnums" ]
end


166
167
168
# File 'lib/nicinfo/utils.rb', line 166

def NicInfo.get_copyright_link links
  get_link "copyright", links
end

.get_country(json_data) ⇒ Object



136
137
138
# File 'lib/nicinfo/utils.rb', line 136

def NicInfo.get_country json_data
  return json_data[ "country" ]
end

.get_descriptions(json_data, config) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/nicinfo/utils.rb', line 77

def NicInfo.get_descriptions json_data, config
  return if !json_data
  if json_data.instance_of?( Hash )
    retval = json_data[ "description" ]
    unless retval.instance_of?( Array )
      config.conf_msgs << "'description' is not an array."
      retval = nil
    end
  else
    config.conf_msgs << "expected object for 'remarks' or 'notices'."
    retval = nil
  end
  return retval
end

.get_ds_data_objs(json_data) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/nicinfo/utils.rb', line 33

def NicInfo.get_ds_data_objs json_data
  secure_dns = NicInfo::get_secure_dns json_data
  if secure_dns.instance_of? Array
    secure_dns = secure_dns[ 0 ]
  end
  return secure_dns[ "dsData" ] if secure_dns
  return nil
end

.get_endAddress(json_data) ⇒ Object



116
117
118
# File 'lib/nicinfo/utils.rb', line 116

def NicInfo.get_endAddress json_data
  return json_data[ "endAddress" ]
end

.get_endAutnum(json_data) ⇒ Object



124
125
126
# File 'lib/nicinfo/utils.rb', line 124

def NicInfo.get_endAutnum json_data
  return json_data[ "endAutnum" ]
end

.get_entitites(json_data) ⇒ Object



92
93
94
# File 'lib/nicinfo/utils.rb', line 92

def NicInfo.get_entitites json_data
  return json_data[ "entities" ]
end

.get_handle(json_data) ⇒ Object



55
56
57
# File 'lib/nicinfo/utils.rb', line 55

def NicInfo.get_handle json_data
  return json_data[ "handle" ]
end

.get_key_data_objs(json_data) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/nicinfo/utils.rb', line 42

def NicInfo.get_key_data_objs json_data
  secure_dns = NicInfo::get_secure_dns json_data
  if secure_dns.instance_of? Array
    secure_dns = secure_dns[ 0 ]
  end
  return secure_dns[ "keyData" ] if secure_dns
  return nil
end

.get_ldhName(json_data) ⇒ Object



69
70
71
# File 'lib/nicinfo/utils.rb', line 69

def NicInfo.get_ldhName json_data
  return json_data[ "ldhName" ]
end


162
163
164
# File 'lib/nicinfo/utils.rb', line 162

def NicInfo.get_license_link links
  get_link "license", links
end


178
179
180
181
182
183
184
185
186
# File 'lib/nicinfo/utils.rb', line 178

def NicInfo.get_link rel, links
  return nil if !links
  links.each do |link|
    if link[ "rel" ] == rel
      return link[ "href" ]
    end
  end
  return nil
end


140
141
142
143
144
145
146
147
148
# File 'lib/nicinfo/utils.rb', line 140

def NicInfo.get_links json_data, config
  retval = json_data[ "links" ]
  return nil unless retval
  if !retval.instance_of?( Array )
    config.conf_msgs << "'links' is not an array."
    retval = nil
  end
  return retval
end

.get_name(json_data) ⇒ Object



128
129
130
# File 'lib/nicinfo/utils.rb', line 128

def NicInfo.get_name json_data
  return json_data[ "name" ]
end

.get_nameservers(json_data) ⇒ Object



108
109
110
# File 'lib/nicinfo/utils.rb', line 108

def NicInfo.get_nameservers json_data
  return json_data[ "nameservers" ]
end

.get_network(json_data) ⇒ Object



100
101
102
# File 'lib/nicinfo/utils.rb', line 100

def NicInfo.get_network json_data
  return json_data[ "network" ]
end

.get_networks(json_data) ⇒ Object



96
97
98
# File 'lib/nicinfo/utils.rb', line 96

def NicInfo.get_networks json_data
  return json_data[ "networks" ]
end

.get_object_class_name(json_data, expected, config) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/nicinfo/utils.rb', line 59

def NicInfo.get_object_class_name json_data, expected, config
  objectClassName =  json_data[ "objectClassName" ]
  if objectClassName == nil
    config.conf_msgs << "Expected 'objectClassName' is not present."
  elsif objectClassName != expected
    config.conf_msgs << "Expected 'objectClassName' to be '#{expected}' but it is '#{objectClassName}'."
  end
  return objectClassName
end


150
151
152
# File 'lib/nicinfo/utils.rb', line 150

def NicInfo.get_related_link links
  get_link "related", links
end

.get_secure_dns(json_data) ⇒ Object



29
30
31
# File 'lib/nicinfo/utils.rb', line 29

def NicInfo.get_secure_dns json_data
  return json_data[ "secureDNS" ]
end


174
175
176
# File 'lib/nicinfo/utils.rb', line 174

def NicInfo.get_self_link links
  get_link "self", links
end

.get_startAddress(json_data) ⇒ Object



112
113
114
# File 'lib/nicinfo/utils.rb', line 112

def NicInfo.get_startAddress json_data
  return json_data[ "startAddress" ]
end

.get_startAutnum(json_data) ⇒ Object



120
121
122
# File 'lib/nicinfo/utils.rb', line 120

def NicInfo.get_startAutnum json_data
  return json_data[ "startAutnum" ]
end


158
159
160
# File 'lib/nicinfo/utils.rb', line 158

def NicInfo.get_tos_link links
  get_link "terms-of-service", links
end

.get_type(json_data) ⇒ Object



132
133
134
# File 'lib/nicinfo/utils.rb', line 132

def NicInfo.get_type json_data
  return json_data[ "type" ]
end

.get_unicodeName(json_data) ⇒ Object



73
74
75
# File 'lib/nicinfo/utils.rb', line 73

def NicInfo.get_unicodeName json_data
  return json_data[ "unicodeName" ]
end

.is_female_name(name) ⇒ Object



26
27
28
# File 'lib/nicinfo/common_names.rb', line 26

def NicInfo::is_female_name name
  is_name "female-first-names.txt", name
end

.is_last_name(name) ⇒ Object



18
19
20
# File 'lib/nicinfo/common_names.rb', line 18

def NicInfo::is_last_name name
  is_name "last-names.txt", name
end

.is_male_name(name) ⇒ Object



22
23
24
# File 'lib/nicinfo/common_names.rb', line 22

def NicInfo::is_male_name name
  is_name "male-first-names.txt", name
end

.is_name(file_name, name) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/nicinfo/common_names.rb', line 30

def NicInfo::is_name file_name, name
  retval = false
  name.gsub! '*',''
  names = name.split( ' ' )

  file = File.new( File.join( File.dirname( __FILE__ ) , file_name ), "r" )
  file.each_line do |line|
    names.each do |n|
      if line.start_with?( n )
        retval = true
        break
      end
    end
  end
  file.close

  return retval
end

.make_safe(url) ⇒ Object



22
23
24
25
26
27
# File 'lib/nicinfo/utils.rb', line 22

def NicInfo.make_safe( url )
  p = URI::Parser.new
  safe = p.escape( url )
  safe = p.escape( safe, "!*'();:@&=+$,/?#[]" )
  return safe
end

.random_portObject



36
37
38
# File 'lib/nicinfo/traceroute.rb', line 36

def NicInfo.random_port
  1024 + rand(64511)
end

.traceroute(host, config) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/nicinfo/traceroute.rb', line 40

def NicInfo.traceroute host, config
  ips = Array.new

  begin
    myname = Socket.gethostname
  rescue SocketError => err_msg
    config.logger.mesg "Can't get my own host name (#{err_msg})."
    exit 1
  end

  config.logger.mesg "Tracing route to #{host}"

  ttl                     = 1
  max_ttl                 = 255
  max_contiguaous_timeout = 16
  localport               = random_port
  dgram_sock              = UDPSocket::new

  begin
    dgram_sock.bind( myname, localport )
  rescue
    localport = random_port
    retry
  end

  begin
    icmp_sock     = Socket.open( Socket::PF_INET, Socket::SOCK_RAW, Socket::IPPROTO_ICMP )
    icmp_sockaddr = Socket.pack_sockaddr_in( localport, myname )
    icmp_sock.bind( icmp_sockaddr )
  rescue SystemCallError => socket_error
    config.logger.mesg "Error with ICMP socket. You probably need to be root: #{socket_error}"
    exit 1
  end


  begin
    dgram_sock.connect( host, 999 )
  rescue SocketError => err_msg
    config.logger.mesg "Can't connect to remote host (#{err_msg})."
    exit 1
  end

  stop_tracing = false
  continguous_timeout = 0
  until stop_tracing
    dgram_sock.setsockopt( 0, Socket::IP_TTL, ttl )
    dgram_sock.send( "RubyRoute says hello!", 0 )

    begin
      Timeout::timeout( 1 ) {
        data, sender = icmp_sock.recvfrom( 8192 )
        # 20th and 21th bytes of IP+ICMP datagram carry the ICMP type and code resp.
        icmp_type = data.unpack( '@20C' )[0]
        icmp_code = data.unpack( '@21C' )[0]
        # Extract the ICMP sender from response.
        ip = Socket.unpack_sockaddr_in( sender )[1].to_s
        ips << ip
        config.logger.mesg "TTL = #{ttl}:  " + ip
        continguous_timeout = 0
        if ( icmp_type == 3 and icmp_code == 13 )
          config.logger.mesg "'Communication Administratively Prohibited' from this hop."
          # ICMP 3/3 is port unreachable and usually means that we've hit the target.
        elsif ( icmp_type == 3 and icmp_code == 3 )
          config.logger.mesg "Destination reached. Trace complete."
          stop_tracing = true
        end
      }
    rescue Timeout::Error
      config.logger.mesg "Timeout error with TTL = #{ttl}!"
      continguous_timeout += 1
    end

    ttl += 1
    stop_tracing = true if ttl > max_ttl
    if continguous_timeout > max_contiguaous_timeout
      stop_tracing = true
      config.logger.mesg "Getting a lot of contiguous timeouts. Prematurely terminating trace."
    end
  end

  ips
end