Class: Ronin::DB::CLI::Commands::Asn Private
- Inherits:
-
ModelCommand
- Object
- Core::CLI::Command
- Ronin::DB::CLI::Command
- 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
--db-file PATH The sqlite3 database file to use
-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
--named NAME Searches for all ASN records containing the 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
#db_connect, #initialize, #list, #load_model, #model, model_file, model_name, #print_record, #query
Methods included from DatabaseOptions
#db_config, #db_connect, included
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.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/ronin/db/cli/commands/asn.rb', line 208 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.
176 177 178 |
# File 'lib/ronin/db/cli/commands/asn.rb', line 176 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.
199 200 201 |
# File 'lib/ronin/db/cli/commands/asn.rb', line 199 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.
143 144 145 146 147 148 149 150 151 |
# File 'lib/ronin/db/cli/commands/asn.rb', line 143 def run db_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.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/ronin/db/cli/commands/asn.rb', line 156 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.
183 184 185 186 187 188 |
# File 'lib/ronin/db/cli/commands/asn.rb', line 183 def update_list_file Support::Network::ASN::List.update( path: [:file], url: [:url] ) end |