Sha256: e99f3e9a9b3a2fd16b17984eeaccb71274a64b19beb5f8be01afd02b5cb77a86

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

require 'netutils/parser'
require 'netutils/arp'

module Alaxala

class ShowARP < Parser
	attr_reader :arps

	def initialize
		@arps = ARPTable.new
		super
		# Date 2017/10/05 21:30:53 JST
		add('Init',	:init, 	/^Date/)
		# VRF: 1 Total: 946 entries
		add('VRF',	:vrf, 	/^VRF/)
		#  IP Address       Linklayer Address  Netif             Expire     Type
		add('Title',	:title,	/^(?: IP Address       Linklayer Address  Netif             Expire     Type|There is no ARP entry.)/)
		# 192.168.0.1      dead.beaf.dead     VLAN9999          4m58s      arpa
		add('Entry',	:entry, /^\s+([0-9\.]+)\s+([0-9a-f\.]+|\(incomplete\))\s+([^\s]+)\s+([^\s]+).*$/)
	end

	def init(l, m)
		# XXX: VRF appears if and only if an IP address is given.
		#changeto('VRF')
		changeto('Title')
	end

	def vrf(l, m)
		changeto('Title')
	end

	def title(l, m)
		changeto('Entry')
	end

	def entry(l, m)
		#
		# remove mediate ``0''s because Alaxala CLI may to accept such 
		# interface name like ``VLAN0620.''
		#
		if m[3] =~ /^([^0-9]+)0+([0-9]+)$/
			interface = "#{$1}#{$2}"
		else
			interface = m[3]
		end
		return if m[2] === '(incomplete)'
		@arps.add(m[1], m[2].downcase, interface, m[4] === 'Static')
	end
end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
netutils-0.1.2 lib/netutils/cli/alaxala/showarp.rb
netutils-0.1.1 lib/netutils/cli/alaxala/showarp.rb