lib/ronin/network/mixins/tcp.rb in ronin-support-0.4.1 vs lib/ronin/network/mixins/tcp.rb in ronin-support-0.5.0.rc1

- old
+ new

@@ -63,10 +63,33 @@ :description => 'TCP server port' protected # + # Tests whether the TCP port, specified by the `host` and `port` + # parameters, is open. + # + # @param [Integer] timeout (5) + # The maximum time to attempt connecting. + # + # @return [Boolean, nil] + # Specifies whether the remote TCP port is open. + # If the connection was not accepted, `nil` will be returned. + # + # @see Network::TCP#tcp_open? + # + # @api public + # + # @since 0.5.0 + # + def tcp_open?(timeout=nil) + print_info "Testing if #{host_port} is open ..." + + super(self.host,self.port,self.local_host,self.local_port,timeout) + end + + # # Opens a TCP connection to the host and port specified by the # `host` and `port` parameters. If the `local_host` and # `local_port` parameters are set, they will be used for # the local host and port of the TCP connection. # @@ -82,11 +105,11 @@ # @example # tcp_connect # => TCPSocket # # @example # tcp_connect do |socket| - # socket.write("GET / HTTP/1.1\n\r\n\r") + # socket.write("GET /\n\n") # # puts socket.readlines # socket.close # end # @@ -145,11 +168,11 @@ # @api public # def tcp_session(&block) print_info "Connecting to #{host_port} ..." - Net.tcp_session(self.host,self.port,self.local_host,self.local_port,&block) + super(self.host,self.port,self.local_host,self.local_port,&block) print_info "Disconnected from #{host_port}" return nil end @@ -187,11 +210,11 @@ # @return [true] # The data was successfully sent. # # @example # buffer = "GET /" + ('A' * 4096) + "\n\r" - # Net.tcp_send(buffer) + # tcp_send(buffer) # # => true # # @see Network::TCP#tcp_send # # @api public @@ -285,19 +308,21 @@ # The newly connected client. # # @return [nil] # # @example - # tcp_single_server do |client| + # tcp_accept do |client| # client.puts 'lol' # end # - # @see Network::TCP#tcp_server_single_server + # @see Network::TCP#tcp_accept # # @api public # - def tcp_single_server(&block) + # @since 0.5.0 + # + def tcp_accept(&block) print_info "Listening on #{server_host_port} ..." super(self.server_port,self.server_host) do |client| client_addr = client.peeraddr client_host = (client_addr[2] || client_addr[3]) @@ -310,9 +335,17 @@ print_info "Disconnected client #{client_host}:#{client_port}" end print_info "Closed #{server_host_port}" return nil + end + + # + # @deprecated + # Deprecated as of 0.5.0. Use {#tcp_accept} instead. + # + def tcp_single_server(&block) + tcp_accept(&block) end private #