class Runc
nc REPL
Constants
- VERSION
:nodoc
Public Class Methods
has_nc()
click to toggle source
check if nc is installed
# File lib/runc.rb, line 52 def self.has_nc system("type -p nc", [:out, :err] => File::NULL) end
Public Instance Methods
ask(prompt)
click to toggle source
prompt user for input
# File lib/runc.rb, line 168 def ask(prompt) res = Readline.readline("#{prompt}> ", true) res.nil? ? (puts; exit) : res end
protocol_file()
click to toggle source
file with internet protocols and ports. More info in 'man services'
# File lib/runc.rb, line 92 def protocol_file '/etc/services' end
read_protocols()
click to toggle source
generate a hash of protocols and port numbers
# File lib/runc.rb, line 98 def read_protocols @protocol = {} File.open(protocol_file) do |f| f.each_line do |l| next if l.match?(/^#|$^/) @protocol[l.split[1].sub(/\/.*/i,'').to_i] = l.split[0] end end # default to http if +port+ is larger than 2000 @protocol.keys.each do |port| @protocol[port] = 'http' if port > 2000 end end
update_header()
click to toggle source
reads a hash from user input hash should be of the form: key1: val1 [, key2: val2 [, …]]
# File lib/runc.rb, line 157 def update_header header_tmp=YAML.load("{#{ask('header')}}") # if +header_tmp+ contains a +port+ key, update the port @port=header_tmp.key?('port') ? header_tmp.delete('port') : @port @header.update(header_tmp) end