Sha256: 8ee7ce9de12df5c0f9418f3f8a7130b5b0c131847f69a8839f54d210a0e72753

Contents?: true

Size: 563 Bytes

Versions: 43

Compression:

Stored size: 563 Bytes

Contents

class Netstat
	
	include RunCommand
	
	command :netstat, :naplev => ""
	
	def data
		headers = false
		output = {}
		command_output.split("\n").each do |line|
			if line[/^Active /,0]
				type = line.split(" ")[1]
			end
			if line[/^Proto /,0]
				fmt = line.split(/ \b/).map {|v| [v.strip.downcase.to_sym,v.length]}
				fmt[fmt.size-1][1] = 99
				next
			end
			next unless fmt
			pkt = {}
			fmt.each do |(name,length)|
				val = line.slice!(0..length-1).strip
				pkt[name] = val
			end
			output[type] ||= []
			output[type] << pkt
		end
		output
	end
	
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
city-watch-0.3.2 lib/city_watch/commands/netstat.rb
city-watch-0.3.1 lib/city_watch/commands/netstat.rb
city-watch-0.3.0 lib/city_watch/commands/netstat.rb