lib/wmap/host_tracker.rb
# Top hostname - sort out most common host-name in the host store in descendant order
Top hostname - sort out most common host-name in the host store in descendant order
Top hostname - sort out most common host - name in the host store in descendant order
def top_hostname (num)
		puts "Sort the host store for the most common hostname. " if @verbose
		h=Hash.new
		host_store=Hash.new
		top=Array.new
		f=File.open(@hosts_file, 'r')
		f.each do |line|
			next unless line =~ /\d+\.\d+\.\d+\.\d+/
			next if is_domain_root?(line.chomp)
			entry=line.chomp.split(%r{\t+|\s+|\,})
			key=entry[0].downcase
			value=entry[1]
			puts "Loading key value pair: #{key} - #{value}" if @verbose
			host_store[key] = Hash.new unless known_hosts.key?(key)
			host_store[key]= value
		end
		f.close
		host_store.keys.map do |key|
			host=key.split('.')
			if h.key?(host[0])
				h[host[0]]+=1
			else
				h[host[0]]=1
			end
		end
		result = h.keys.sort { |a,b| h[b] <=> h[a] } 
		num = result.size if result.size < num
		for i in 0...num
			top.push(result[i])
		end
		return top
	rescue Exception => ee
		puts "Exception on method #{__method__}: #{ee}"
		return nil
	end
def top_hostname ( num ) puts "Sort the host store for the most common hostname. " if @verbose h = Hash . new host_store = Hash . new top = Array . new f = File . open ( @hosts_file , 'r' ) f . each do | line | next unless line =~ / \d + \. \d + \. \d + \. \d + / next if is_domain_root? ( line . chomp ) entry = line . chomp . split ( %r{ \t +| \s +| \, } ) key = entry [ 0 ] . downcase value = entry [ 1 ] puts "Loading key value pair: #{key} - #{value}" if @verbose host_store [ key ] = Hash . new unless known_hosts . key? ( key ) host_store [ key ] = value end f . close host_store . keys . map do | key | host = key . split ( '.' ) if h . key? ( host [ 0 ] ) h [ host [ 0 ] ] += 1 else h [ host [ 0 ] ] = 1 end end result = h . keys . sort { | a , b | h [ b ] <=> h [ a ] } num = result . size if result . size < num for i in 0 ... num top . push ( result [ i ] ) end return top rescue Exception => ee puts "Exception on method #{__method__}: #{ee}" return nil end
Top hostname - sort out most common host-name in the host store in descendant order
Top hostname - sort out most common host - name in the host store in descendant order
# Build a host table from the host file # skip the domain roots in the host list # Sort by value descendantly
num
<not_specific>