Class: Ronin::CLI::Commands::Ip Private

Inherits:
ValueProcessorCommand show all
Defined in:
lib/ronin/cli/commands/ip.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 processes IP addresses.

Usage

ronin ip [options] [IP ... | --public | --local]

Options

-f, --file FILE                  Optional file to read values from
-P, --public                     Gets the machine's public IP address
-L, --local                      Gets the machine's local IP address
-r, --reverse                    Prints the IP address in reverse name format
-X, --hex                        Converts the IP address to hexadecimal format
-D, --decimal                    Converts the IP address to decimal format
-O, --octal                      Converts the IP address to octal format
-B, --binary                     Converts the IP address to binary format
    --hex-octet                  Converts the IP address to hexadecimal format by octet
    --octal-octet                Converts the IP address to octal format by octet
    --ipv6-compat                Converts the IPv4 address to an IPv6 compatible address
    --ipv6-expanded              Expands a shortened or compressed IPv6 address
-C, --cidr NETMASK               Converts the IP address into a CIDR range
-H, --host                       Converts the IP address to a host name
-p, --port PORT                  Appends the port number to each IP
-U, --uri                        Converts the IP address into a URI
    --uri-scheme SCHEME          The scheme for the URI (Default: http)
    --uri-port PORT              The port for the URI
    --uri-path /PATH             The path for the URI (Default: /)
    --uri-query STRING           The query string for the URI
    --http                       Converts the IP address into a http:// URI
    --https                      Converts the IP address into a https:// URI
-h, --help                       Print help information

Arguments

[IP ...]                         The IP address(es) to process

Examples

ronin ip --public
ronin ip --local
ronin ip --decimal 1.2.3.4
ronin ip --cidr 20 1.2.3.4
ronin ip --host 192.30.255.113

Since:

  • 2.0.0

Instance Attribute Summary

Attributes inherited from ValueProcessorCommand

#files

Instance Method Summary collapse

Methods inherited from ValueProcessorCommand

#initialize, #process_file

Constructor Details

This class inherits a constructor from Ronin::CLI::ValueProcessorCommand

Instance Method Details

#format_ip(ip) ⇒ String

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.

Formats an IP address.

Parameters:

  • ip (Ronin::Support::Network::IP)

    The IP address to format.

Returns:

  • (String)

    The formatted IP address.

Since:

  • 2.0.0



242
243
244
245
246
247
248
# File 'lib/ronin/cli/commands/ip.rb', line 242

def format_ip(ip)
  if ip.ipv4?
    format_ipv4(ip)
  else
    format_ipv6(ip)
  end
end

#process_value(ip) ⇒ 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.

Processes an individual IP address.

Parameters:

  • ip (String)

    The IP address string to process.

Since:

  • 2.0.0



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/ronin/cli/commands/ip.rb', line 205

def process_value(ip)
  ip = Support::Network::IP.new(ip)

  if options[:reverse]
    puts ip.reverse
  elsif options[:cidr]
    ip = Support::Network::IP.new("#{ip}/#{options[:cidr]}")

    puts "#{ip}/#{ip.prefix}"
  elsif options[:host]
    if (host = ip.host)
      puts host
    end
  elsif options[:port]
    puts "#{format_ip(ip)}:#{options[:port]}"
  elsif options[:uri]
    puts URI::Generic.build(
      scheme: options[:uri_scheme],
      host:   format_ip(ip),
      port:   options[:uri_port],
      path:   options[:uri_path],
      query:  options[:uri_query]
    )
  else
    puts format_ip(ip)
  end
end

#run(*ips) ⇒ 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 ip command.

Parameters:

  • ips (Array<String>)

    Additional IP arguments to process.

Since:

  • 2.0.0



184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/ronin/cli/commands/ip.rb', line 184

def run(*ips)
  if options[:public]
    if (address = Support::Network::IP.public_address)
      puts address
    else
      print_error 'failed to lookup public IP address using https://ipinfo.io/ip'
      exit(1)
    end
  elsif options[:local]
    puts Support::Network::IP.local_address
  else
    super(*ips)
  end
end