Class: Ronin::CLI::Commands::Asn Private

Inherits:
Ronin::CLI::Command show all
Includes:
CommandKit::Options::Verbose, Core::CLI::Logging
Defined in:
lib/ronin/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 or searches for ASN information.

Usage

ronin asn [options] [-v | --enum-ips] {-n,--number NUM | -c,--country COUNTRY | -N,--name NAME | -I,--ip IP}

Options

-v, --verbose                    Enables verbose output
-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: ~/.cache/ronin/ronin-support/ip2asn-combined.tsv.gz)
-u, --update                     Updates the ASN list file
-n, --number NUM|AS...           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
-E, --enum-ips                   Enumerate over the IPs within the ASN ranges
-h, --help                       Print help information

Examples

ronin asn -v -n 15133
ronin asn -v -I 93.184.216.34
ronin asn -C US
ronin asn -N EDGECAST
ronin asn --enum-ips -n 15133
ronin asn --enum-ips -N EDGECAST

Since:

  • 2.0.0

Instance Method Summary collapse

Instance Method Details

#downloadObject

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.

Downloads the ASN list file.

Since:

  • 2.0.0



171
172
173
174
175
176
177
178
179
180
# File 'lib/ronin/cli/commands/asn.rb', line 171

def download
  if verbose?
    log_info "Downloading ASN list from #{options[:url]} to #{options[:file]} ..."
  end

  Support::Network::ASN::List.download(
    url:  options[:url],
    path: options[:file]
  )
end

#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.

Yields:

  • (record)

Yield Parameters:

  • record (Ronin::Support::Network::ASN::Record)

Returns:

  • (Enumerator)

Since:

  • 2.0.0



205
206
207
# File 'lib/ronin/cli/commands/asn.rb', line 205

def list_file(&block)
  Support::Network::ASN::List.parse(options[:file],&block)
end

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.

Prints an ASN record.

Parameters:

  • record (Ronin::Support::Network::ASN::Record)

Since:

  • 2.0.0



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/ronin/cli/commands/asn.rb', line 263

def print_asn_record(record)
  if options[:enum_ips]
    record.range.each do |ip|
      puts ip
    end
  elsif options[:verbose]
    puts "[ AS#{record.number} ]"
    puts
    puts "ASN:      #{record.number}"
    puts "IP range: #{record.range}"
    puts "Country:  #{record.country_code}"
    puts "Name:     #{record.name}"
    puts
  else
    puts record
  end
end

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.

Prints a collection of ASN records.

Parameters:

  • records (Ronin::Support::Network::ASN::RecordSet)

Since:

  • 2.0.0



252
253
254
255
256
# File 'lib/ronin/cli/commands/asn.rb', line 252

def print_asn_records(records)
  records.each do |record|
    print_asn_record(record)
  end
end

#query_ip(ip) ⇒ Ronin::Support::Network::ASN::DNSRecord

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.

Queries the ASN record for the given IP address.

Parameters:

  • ip (String)

Returns:

  • (Ronin::Support::Network::ASN::DNSRecord)

Since:

  • 2.0.0



216
217
218
# File 'lib/ronin/cli/commands/asn.rb', line 216

def query_ip(ip)
  Support::Network::ASN.query(ip)
end

#runObject

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 asn command.

Since:

  • 2.0.0



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/ronin/cli/commands/asn.rb', line 142

def run
  if !File.file?(options[:file])
    download
  elsif options[:update] || stale?
    update
  end

  if options[:ip]
    if (record = query_ip(options[:ip]))
      print_asn_record(record)
    else
      print_error "could not find a record for the IP: #{options[:ip]}"
      exit(-1)
    end
  else
    print_asn_records(search_asn_records)
  end
end

#search_asn_recordsRonin::Support::Network::ASN::RecordSet

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.

Queries ASN records.

Returns:

  • (Ronin::Support::Network::ASN::RecordSet)

Since:

  • 2.0.0



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/ronin/cli/commands/asn.rb', line 225

def search_asn_records
  records = Support::Network::ASN::RecordSet.new(list_file)

  if    options[:ipv4]  then records = records.ipv4
  elsif options[:ipv6]  then records = records.ipv6
  end

  if options[:country_code]
    records = records.country(options[:country_code])
  end

  if options[:number]
    records = records.number(options[:number])
  end

  if options[:name]
    records = records.name(options[:name])
  end

  return records
end

#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.

Returns:

  • (Boolean)

Since:

  • 2.0.0



164
165
166
# File 'lib/ronin/cli/commands/asn.rb', line 164

def stale?
  Support::Network::ASN::List.stale?(options[:file])
end

#updateObject

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.

Since:

  • 2.0.0



185
186
187
188
189
190
191
192
193
194
# File 'lib/ronin/cli/commands/asn.rb', line 185

def update
  if verbose?
    log_info "Updating ASN list file #{options[:file]} ..."
  end

  Support::Network::ASN::List.update(
    url:  options[:url],
    path: options[:file]
  )
end