Class: NicInfo::Ip

Inherits:
Object
  • Object
show all
Defined in:
lib/nicinfo/ip.rb

Overview

deals with RDAP IP network structures

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Ip

Returns a new instance of Ip.



37
38
39
40
41
42
# File 'lib/nicinfo/ip.rb', line 37

def initialize config
  @config = config
  @common = CommonJson.new config
  @entities = Array.new
  @asEventActors = Array.new
end

Instance Attribute Details

#asEventActorsObject

Returns the value of attribute asEventActors.



35
36
37
# File 'lib/nicinfo/ip.rb', line 35

def asEventActors
  @asEventActors
end

#entitiesObject

Returns the value of attribute entities.



35
36
37
# File 'lib/nicinfo/ip.rb', line 35

def entities
  @entities
end

#objectclassObject

Returns the value of attribute objectclass.



35
36
37
# File 'lib/nicinfo/ip.rb', line 35

def objectclass
  @objectclass
end

Instance Method Details

#displayObject



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
# File 'lib/nicinfo/ip.rb', line 50

def display
  @config.logger.start_data_item
  @config.logger.data_title "[ IP NETWORK ]"
  @config.logger.terse "Handle", NicInfo::get_handle( @objectclass ), NicInfo::AttentionType::SUCCESS
  @config.logger.extra "Object Class Name", NicInfo::get_object_class_name( @objectclass, "ip network", @config )
  start_addr = NicInfo.get_startAddress( @objectclass )
  if start_addr.include?( '/' )
    @config.conf_msgs << "start IP #{start_addr} is not an IP address (possibly a CIDR)"
  end
  @config.logger.terse "Start Address", start_addr , NicInfo::AttentionType::SUCCESS
  end_addr = NicInfo.get_endAddress( @objectclass )
  if end_addr.include?( '/' )
    @config.conf_msgs << "end IP #{end_addr} is not an IP address (possibly a CIDR)"
  end
  @config.logger.terse "End Address", end_addr, NicInfo::AttentionType::SUCCESS
  @config.logger.terse "CIDRs", get_CIDRs
  @config.logger.datum "IP Version", @objectclass[ "ipVersion" ]
  @config.logger.extra "Name", NicInfo.get_name( @objectclass )
  @config.logger.terse "Country", NicInfo.get_country( @objectclass )
  @config.logger.datum "Type", NicInfo.get_type( @objectclass )
  @config.logger.extra "Parent Handle", @objectclass[ "parentHandle" ]
  @common.display_status @objectclass
  @common.display_events @objectclass
  @common.display_as_events_actors @asEventActors
  @common.display_remarks @objectclass
  @common.display_links( get_cn, @objectclass )
  @config.logger.end_data_item
end

#get_CIDRsObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/nicinfo/ip.rb', line 92

def get_CIDRs
  startAddress = NicInfo.get_startAddress @objectclass
  endAddress = NicInfo.get_endAddress @objectclass
  if startAddress and endAddress
    cidrs = find_cidrs(startAddress, endAddress)
    return cidrs.join(', ')
  elsif startAddress
    return NetAddr::CIDR.create(startAddress).to_s
  elsif endAddress
    return NetAddr::CIDR.create(endAddress).to_s
  else
    return ""
  end
end

#get_cnObject



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

def get_cn
  handle = NicInfo::get_handle @objectclass
  if !handle
    startAddress = NicInfo.get_startAddress @objectclass
    handle << startAddress if startAddress
    endAddress = NicInfo.get_endAddress @objectclass
    handle << " - " if startAddress and endAddress
    handle << endAddress if endAddress
  end
  return handle if handle
  return "(unidentifiable network #{object_id})"
end

#process(json_data) ⇒ Object



44
45
46
47
48
# File 'lib/nicinfo/ip.rb', line 44

def process json_data
  @objectclass = json_data
  @entities = @common.process_entities @objectclass
  return self
end

#to_nodeObject



107
108
109
# File 'lib/nicinfo/ip.rb', line 107

def to_node
  DataNode.new( get_cn, nil, NicInfo::get_self_link( NicInfo::get_links( @objectclass, @config ) ) )
end