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
--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
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.
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.
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 [: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.
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 [: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 |