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



227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/ronin/cli/commands/ip.rb', line 227

def format_ip(ip)
  if options[:hex]
    "0x%x" % ip.to_i
  elsif options[:decimal]
    "%u" % ip.to_i
  elsif options[:octal]
    "0%o" % ip.to_i
  elsif options[:binary]
    "%b" % ip.to_i
  else
    ip.to_s
  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



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/ronin/cli/commands/ip.rb', line 190

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



169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/ronin/cli/commands/ip.rb', line 169

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