Sha256: a3167dfdc659766f4d450dcda4bec77ba94279b7471004fc053c14cd47546942

Contents?: true

Size: 1.35 KB

Versions: 25

Compression:

Stored size: 1.35 KB

Contents

require 'yaml/store'

module SSHScan
  # Create and/or maintain a fingerprint database using YAML Store.
  class FingerprintDatabase
    def initialize(database_name)
      @store = YAML::Store.new(database_name)
    end

    # Empty the fingerprints database for given IP.
    # @param ip [String] IP for which fingerprints should be
    #   cleared.
    def clear_fingerprints(ip)
      @store.transaction do
        @store[ip] = []
      end
    end

    # Insert a (fingerprint, IP) record.
    # @param fingerprint [String] fingerprint to insert
    # @param ip [String] IP for which fingerprint has to be added
    def add_fingerprint(fingerprint, ip)
      @store.transaction do
        @store[ip] = [] if @store[ip].nil?
        @store[ip] << fingerprint
      end
    end

    # Find IPs that have the given fingerprint.
    # @param fingerprint [String] fingerprint for which search
    #   should be performed
    # @return [Array<String>] return unique IPs for which the given
    #   fingerprint has an entry
    def find_fingerprints(fingerprint)
      ip_matches = []

      @store.transaction(true) do
        @store.roots.each do |ip|
          @store[ip].each do |other_fingerprint|
            if fingerprint == other_fingerprint
              ip_matches << ip
            end
          end
        end
      end

      return ip_matches.uniq
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
ssh_scan-0.0.44 lib/ssh_scan/fingerprint_database.rb
ssh_scan-0.0.43 lib/ssh_scan/fingerprint_database.rb
ssh_scan-0.0.42 lib/ssh_scan/fingerprint_database.rb
ssh_scan-0.0.41 lib/ssh_scan/fingerprint_database.rb
ssh_scan-0.0.40 lib/ssh_scan/fingerprint_database.rb
ssh_scan-0.0.39 lib/ssh_scan/fingerprint_database.rb
ssh_scan-0.0.38 lib/ssh_scan/fingerprint_database.rb
ssh_scan-0.0.38.pre lib/ssh_scan/fingerprint_database.rb
ssh_scan-0.0.37 lib/ssh_scan/fingerprint_database.rb
ssh_scan-0.0.36 lib/ssh_scan/fingerprint_database.rb
ssh_scan-0.0.35 lib/ssh_scan/fingerprint_database.rb
ssh_scan-0.0.34 lib/ssh_scan/fingerprint_database.rb
ssh_scan-0.0.33 lib/ssh_scan/fingerprint_database.rb
ssh_scan-0.0.32 lib/ssh_scan/fingerprint_database.rb
ssh_scan-0.0.31 lib/ssh_scan/fingerprint_database.rb
ssh_scan-0.0.30 lib/ssh_scan/fingerprint_database.rb
ssh_scan-0.0.29 lib/ssh_scan/fingerprint_database.rb
ssh_scan-0.0.28 lib/ssh_scan/fingerprint_database.rb
ssh_scan-0.0.27 lib/ssh_scan/fingerprint_database.rb
ssh_scan-0.0.26 lib/ssh_scan/fingerprint_database.rb