Sha256: f871036b53acbd8f2799b5d5ac52bcd08bacf98f567e90143dd11593c980deb1

Contents?: true

Size: 951 Bytes

Versions: 7

Compression:

Stored size: 951 Bytes

Contents

# 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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
netdisco-0.0.8 lib/netdisco/peer.rb
netdisco-0.0.7 lib/netdisco/peer.rb
netdisco-0.0.6 lib/netdisco/peer.rb
netdisco-0.0.5 lib/netdisco/peer.rb
netdisco-0.0.4 lib/netdisco/peer.rb
netdisco-0.0.3 lib/netdisco/peer.rb
netdisco-0.0.2 lib/netdisco/peer.rb