class Ronin::CLI::Commands::Asn
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
Public Instance Methods
download()
click to toggle source
Downloads the ASN list file.
# 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(&block)
click to toggle source
Parses the ASN list file.
@yield [record]
@yieldparam [Ronin::Support::Network::ASN::Record] record
@return [Enumerator]
# File lib/ronin/cli/commands/asn.rb, line 205 def list_file(&block) Support::Network::ASN::List.parse(options[:file],&block) end
print_asn_record(record)
click to toggle source
Prints an ASN record.
@param [Ronin::Support::Network::ASN::Record] record
# 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
print_asn_records(records)
click to toggle source
Prints a collection of ASN records.
@param [Ronin::Support::Network::ASN::RecordSet] records
# 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)
click to toggle source
Queries the ASN record for the given IP address.
@param [String] ip
@return [Ronin::Support::Network::ASN::DNSRecord]
# File lib/ronin/cli/commands/asn.rb, line 216 def query_ip(ip) Support::Network::ASN.query(ip) end
run()
click to toggle source
Runs the ‘ronin asn` command.
# 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_records()
click to toggle source
Queries ASN records.
@return [Ronin::Support::Network::ASN::RecordSet]
# 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?()
click to toggle source
Determines if the ASN list file is stale.
# File lib/ronin/cli/commands/asn.rb, line 164 def stale? Support::Network::ASN::List.stale?(options[:file]) end
update()
click to toggle source
Updates the ASN list file.
# 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