Class: Ronin::CLI::Commands::Ip Private
- Inherits:
-
ValueProcessorCommand
- Object
- Core::CLI::Command
- Ronin::CLI::Command
- ValueProcessorCommand
- Ronin::CLI::Commands::Ip
- 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 [] [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
Instance Attribute Summary
Attributes inherited from ValueProcessorCommand
Instance Method Summary collapse
-
#format_ip(ip) ⇒ String
private
Formats an IP address.
-
#process_value(ip) ⇒ Object
private
Processes an individual IP address.
-
#run(*ips) ⇒ Object
private
Runs the
ronin ip
command.
Methods inherited from ValueProcessorCommand
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.
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 [:hex] "0x%x" % ip.to_i elsif [:decimal] "%u" % ip.to_i elsif [:octal] "0%o" % ip.to_i elsif [: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.
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 [:reverse] puts ip.reverse elsif [:cidr] ip = Support::Network::IP.new("#{ip}/#{[:cidr]}") puts "#{ip}/#{ip.prefix}" elsif [:host] if (host = ip.host) puts host end elsif [:port] puts "#{format_ip(ip)}:#{[:port]}" elsif [:uri] puts URI::Generic.build( scheme: [:uri_scheme], host: format_ip(ip), port: [:uri_port], path: [:uri_path], query: [: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.
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 [: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 [:local] puts Support::Network::IP.local_address else super(*ips) end end |