Class: SSHScan::FingerprintDatabase
- Inherits:
-
Object
- Object
- SSHScan::FingerprintDatabase
- Defined in:
- lib/ssh_scan/fingerprint_database.rb
Overview
Create and/or maintain a fingerprint database using YAML Store.
Instance Method Summary collapse
-
#add_fingerprint(fingerprint, ip) ⇒ Object
Insert a (fingerprint, IP) record.
-
#clear_fingerprints(ip) ⇒ Object
Empty the fingerprints database for given IP.
-
#find_fingerprints(fingerprint) ⇒ Array<String>
Find IPs that have the given fingerprint.
-
#initialize(database_name) ⇒ FingerprintDatabase
constructor
A new instance of FingerprintDatabase.
Constructor Details
#initialize(database_name) ⇒ FingerprintDatabase
Returns a new instance of FingerprintDatabase.
6 7 8 |
# File 'lib/ssh_scan/fingerprint_database.rb', line 6 def initialize(database_name) @store = YAML::Store.new(database_name) end |
Instance Method Details
#add_fingerprint(fingerprint, ip) ⇒ Object
Insert a (fingerprint, IP) record.
22 23 24 25 26 27 |
# File 'lib/ssh_scan/fingerprint_database.rb', line 22 def add_fingerprint(fingerprint, ip) @store.transaction do @store[ip] = [] if @store[ip].nil? @store[ip] << fingerprint end end |
#clear_fingerprints(ip) ⇒ Object
Empty the fingerprints database for given IP.
13 14 15 16 17 |
# File 'lib/ssh_scan/fingerprint_database.rb', line 13 def clear_fingerprints(ip) @store.transaction do @store[ip] = [] end end |
#find_fingerprints(fingerprint) ⇒ Array<String>
Find IPs that have the given fingerprint.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ssh_scan/fingerprint_database.rb', line 34 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 |