Class: Ronin::DB::CLI::Commands::Asn Private
- Inherits:
-
ModelCommand
- Object
- Core::CLI::Command
- Ronin::DB::CLI::Command
- DatabaseCommand
- ModelCommand
- Ronin::DB::CLI::Commands::Asn
- Includes:
- Core::CLI::Logging
- Defined in:
- lib/ronin/db/cli/commands/asn.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Queries and updates ASNs.
Usage
ronin-db asn [options]
Options
--db NAME The database to connect to (Default: default)
--db-uri URI The database URI to connect to
-v, --verbose Enables verbose output
-n, --number INT Searches for all ASN records with the AS number
-C XX|None|Unknown, Searches for all ASN records with the country code
--country-code
-N, --name NAME Searches for all ASN records with the matching name
-I, --ip IP Queries the ASN record for the IP
-4, --ipv4 Filter ASN records for only IPv4 ranges
-6, --ipv6 Filter ASN records for only IPv6 ranges
-u, --update Updates the ASN records
-U, --url URI Overrides the default ASN list URL (Default: https://iptoasn.com/data/ip2asn-combined.tsv.gz)
-f, --file FILE Overrides the default ASN list file (Default: /home/postmodern/.local/share/ronin/ronin-support/ip2asn-combined.tsv.gz)
-h, --help Print help information
Constant Summary
Constants included from URIMethods
Instance Attribute Summary
Attributes inherited from ModelCommand
Instance Method Summary collapse
-
#import_asn_record(record) ⇒ Object
private
Saves a parsed ASN record.
-
#is_list_file_stale? ⇒ Boolean
private
Determines if the ASN list file is stale.
-
#parse_list_file {|record| ... } ⇒ Enumerator
private
Parses the ASN list file.
-
#run ⇒ Object
private
Runs the
ronin-db asn
command. -
#update ⇒ Object
private
Updates the ASN file and populates the database.
-
#update_list_file ⇒ Object
private
Updates the ASN list file.
Methods inherited from ModelCommand
#connect, #initialize, #list, #load_model, #model, model_file, model_name, #print_record, #query
Methods inherited from DatabaseCommand
Methods included from URIMethods
#normalize_adapter, #normalize_sqlite3_path, #parse_uri
Constructor Details
This class inherits a constructor from Ronin::DB::CLI::ModelCommand
Instance Method Details
#import_asn_record(record) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Saves a parsed ASN record.
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/ronin/db/cli/commands/asn.rb', line 198 def import_asn_record(record) asn = model.new( version: if record.ipv6? then 6 else 4 end, range_start: record.range.begin, range_end: record.range.end, number: record.number, country_code: record.country_code, name: record.name ) # bypass validations since we're importing from a known good source asn.save(validate: false) end |
#is_list_file_stale? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determines if the ASN list file is stale.
166 167 168 |
# File 'lib/ronin/db/cli/commands/asn.rb', line 166 def is_list_file_stale? Support::Network::ASN::List.stale?([:file]) end |
#parse_list_file {|record| ... } ⇒ Enumerator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parses the ASN list file.
189 190 191 |
# File 'lib/ronin/db/cli/commands/asn.rb', line 189 def parse_list_file(&block) Support::Network::ASN::List.parse([:file],&block) end |
#run ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Runs the ronin-db asn
command.
133 134 135 136 137 138 139 140 141 |
# File 'lib/ronin/db/cli/commands/asn.rb', line 133 def run connect if [:update] update else list end end |
#update ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Updates the ASN file and populates the database.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/ronin/db/cli/commands/asn.rb', line 146 def update if is_list_file_stale? log_info "Updating ASN list file ..." update_list_file end # clear the table instead of trying to diff the list with the table model.delete_all model.transaction do parse_list_file do |record| log_info "Importing #{record} ..." import_asn_record(record) end end end |
#update_list_file ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Updates the ASN list file.
173 174 175 176 177 178 |
# File 'lib/ronin/db/cli/commands/asn.rb', line 173 def update_list_file Support::Network::ASN::List.update( path: [:file], url: [:url] ) end |