Class: Ronin::CLI::Commands::Asn Private
- Inherits:
-
Ronin::CLI::Command
- Object
- Core::CLI::Command
- Ronin::CLI::Command
- Ronin::CLI::Commands::Asn
- 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
Instance Method Summary collapse
-
#download ⇒ Object
private
Downloads the ASN list file.
-
#list_file {|record| ... } ⇒ Enumerator
private
Parses the ASN list file.
-
#print_asn_record(record) ⇒ Object
private
Prints an ASN record.
-
#print_asn_records(records) ⇒ Object
private
Prints a collection of ASN records.
-
#query_ip(ip) ⇒ Ronin::Support::Network::ASN::DNSRecord
private
Queries the ASN record for the given IP address.
-
#run ⇒ Object
private
Runs the
ronin asn
command. -
#search_asn_records ⇒ Ronin::Support::Network::ASN::RecordSet
private
Queries ASN records.
-
#stale? ⇒ Boolean
private
Determines if the ASN list file is stale.
-
#update ⇒ Object
private
Updates the ASN list file.
Instance Method Details
#download ⇒ 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.
Downloads the ASN list file.
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 #{[:url]} to #{[:file]} ..." end Support::Network::ASN::List.download( url: [:url], path: [: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.
205 206 207 |
# File 'lib/ronin/cli/commands/asn.rb', line 205 def list_file(&block) Support::Network::ASN::List.parse([:file],&block) end |
#print_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.
Prints an ASN record.
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 [:enum_ips] record.range.each do |ip| puts ip end elsif [: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) ⇒ 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.
Prints a collection of ASN records.
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.
216 217 218 |
# File 'lib/ronin/cli/commands/asn.rb', line 216 def query_ip(ip) Support::Network::ASN.query(ip) 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 asn
command.
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?([:file]) download elsif [:update] || stale? update end if [:ip] if (record = query_ip([:ip])) print_asn_record(record) else print_error "could not find a record for the IP: #{[:ip]}" exit(-1) end else print_asn_records(search_asn_records) end end |
#search_asn_records ⇒ Ronin::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.
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 [:ipv4] then records = records.ipv4 elsif [:ipv6] then records = records.ipv6 end if [:country_code] records = records.country([:country_code]) end if [:number] records = records.number([:number]) end if [:name] records = records.name([: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.
164 165 166 |
# File 'lib/ronin/cli/commands/asn.rb', line 164 def stale? Support::Network::ASN::List.stale?([:file]) 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 list file.
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 #{[:file]} ..." end Support::Network::ASN::List.update( url: [:url], path: [:file] ) end |