# frozen_string_literal: true class Netdisco class Peer # 类对象方法属性 attr_accessor :ip, :raw_ip, :raw_name, :src, :dst, :oid # 初始化函数 def initialize @ip = nil # Best guess of system IP @name = nil # Reverse of said IP @raw_ip = nil # IP as seen in polling @raw_name = nil # Name as seen in polling @src = nil # SRC/local interface @dst = nil # DST/remote interface @oid = {} # Hash of oids collected end # 设置邻居名称 def name @name ||= DNS.getname @ip end # 将邻居对象转换为 HASH def to_h { "ip" => ip.to_s, "name" => name.to_s, "interface" => { "source" => src.to_s, "destination" => dst.to_s }, "raw" => { "ip" => raw_ip.to_s, "name" => raw_name.to_s } } end end end