Module: Ronin::Network::Mixins::TCP
Overview
Adds TCP convenience methods and connection parameters to a class.
Defines the following parameters:
host(String) - TCP host.port(Integer) - TCP port.local_host(String) - TCP local host.local_port(Integer) - TCP local port.server_host(String) - TCP server host.server_port(Integer) - TCP server port.
Class Method Summary (collapse)
-
+ (Object) host
TCP host.
-
+ (Object) host=(value)
TCP host.
-
+ (Object) local_host
TCP local host.
-
+ (Object) local_host=(value)
TCP local host.
-
+ (Object) local_port
TCP local port.
-
+ (Object) local_port=(value)
TCP local port.
-
+ (Object) port
TCP port.
-
+ (Object) port=(value)
TCP port.
-
+ (Object) server_host
TCP server host.
-
+ (Object) server_host=(value)
TCP server host.
-
+ (Object) server_port
TCP server port.
-
+ (Object) server_port=(value)
TCP server port.
Instance Method Summary (collapse)
-
- (Object) host
TCP host.
-
- (Object) host=(value)
TCP host.
-
- (Object) local_host
TCP local host.
-
- (Object) local_host=(value)
TCP local host.
-
- (Object) local_port
TCP local port.
-
- (Object) local_port=(value)
TCP local port.
-
- (Object) port
TCP port.
-
- (Object) port=(value)
TCP port.
-
- (Object) server_host
TCP server host.
-
- (Object) server_host=(value)
TCP server host.
-
- (Object) server_port
TCP server port.
-
- (Object) server_port=(value)
TCP server port.
-
- (nil) tcp_accept {|client| ... }
protected
Creates a new temporary TCPServer object listening on
server_hostandserver_portparameters. -
- (String) tcp_banner {|banner| ... }
protected
Connects to the host and port specified by the
hostandportparameters, reads the banner then closes the connection. -
- (TCPSocket) tcp_connect {|socket| ... }
protected
Opens a TCP connection to the host and port specified by the
hostandportparameters. -
- (TCPSocket) tcp_connect_and_send(data) {|socket| ... }
protected
Connects to the host and port specified by the
hostandportparameters, then sends the given data. -
- (Boolean?) tcp_open?(timeout = nil)
protected
Tests whether the TCP port, specified by the
hostandportparameters, is open. -
- (true) tcp_send(data)
protected
Connects to the host and port specified by the
hostandportparameters, sends the given data and then disconnects. -
- (TCPServer) tcp_server {|server| ... }
protected
Creates a new TCPServer object listening on the
server_hostandserver_portparameters. -
- (nil) tcp_server_session {|server| ... }
protected
Creates a new temporary TCPServer object listening on the
server_hostandserver_portparameters. -
- (nil) tcp_session {|socket| ... }
protected
Creates a TCP session to the host and port specified by the
hostandportparameters. -
- (Object) tcp_single_server(&block)
protected
deprecated
Deprecated.
Deprecated as of 0.5.0. Use #tcp_accept instead.
Methods included from Mixin
Methods included from TCP
Class Method Details
+ (Object) host
TCP host
42 43 |
# File 'lib/ronin/network/mixins/tcp.rb', line 42 parameter :host, :type => String, :description => 'TCP host' |
+ (Object) host=(value)
TCP host
42 43 |
# File 'lib/ronin/network/mixins/tcp.rb', line 42 parameter :host, :type => String, :description => 'TCP host' |
+ (Object) local_host
TCP local host
50 51 |
# File 'lib/ronin/network/mixins/tcp.rb', line 50 parameter :local_host, :type => String, :description => 'TCP local host' |
+ (Object) local_host=(value)
TCP local host
50 51 |
# File 'lib/ronin/network/mixins/tcp.rb', line 50 parameter :local_host, :type => String, :description => 'TCP local host' |
+ (Object) local_port
TCP local port
54 55 |
# File 'lib/ronin/network/mixins/tcp.rb', line 54 parameter :local_port, :type => Integer, :description => 'TCP local port' |
+ (Object) local_port=(value)
TCP local port
54 55 |
# File 'lib/ronin/network/mixins/tcp.rb', line 54 parameter :local_port, :type => Integer, :description => 'TCP local port' |
+ (Object) port
TCP port
46 47 |
# File 'lib/ronin/network/mixins/tcp.rb', line 46 parameter :port, :type => Integer, :description => 'TCP port' |
+ (Object) port=(value)
TCP port
46 47 |
# File 'lib/ronin/network/mixins/tcp.rb', line 46 parameter :port, :type => Integer, :description => 'TCP port' |
+ (Object) server_host
TCP server host
58 59 |
# File 'lib/ronin/network/mixins/tcp.rb', line 58 parameter :server_host, :type => String, :description => 'TCP server host' |
+ (Object) server_host=(value)
TCP server host
58 59 |
# File 'lib/ronin/network/mixins/tcp.rb', line 58 parameter :server_host, :type => String, :description => 'TCP server host' |
+ (Object) server_port
TCP server port
62 63 |
# File 'lib/ronin/network/mixins/tcp.rb', line 62 parameter :server_port, :type => Integer, :description => 'TCP server port' |
+ (Object) server_port=(value)
TCP server port
62 63 |
# File 'lib/ronin/network/mixins/tcp.rb', line 62 parameter :server_port, :type => Integer, :description => 'TCP server port' |
Instance Method Details
- (Object) host
TCP host
42 43 |
# File 'lib/ronin/network/mixins/tcp.rb', line 42 parameter :host, :type => String, :description => 'TCP host' |
- (Object) host=(value)
TCP host
42 43 |
# File 'lib/ronin/network/mixins/tcp.rb', line 42 parameter :host, :type => String, :description => 'TCP host' |
- (Object) local_host
TCP local host
50 51 |
# File 'lib/ronin/network/mixins/tcp.rb', line 50 parameter :local_host, :type => String, :description => 'TCP local host' |
- (Object) local_host=(value)
TCP local host
50 51 |
# File 'lib/ronin/network/mixins/tcp.rb', line 50 parameter :local_host, :type => String, :description => 'TCP local host' |
- (Object) local_port
TCP local port
54 55 |
# File 'lib/ronin/network/mixins/tcp.rb', line 54 parameter :local_port, :type => Integer, :description => 'TCP local port' |
- (Object) local_port=(value)
TCP local port
54 55 |
# File 'lib/ronin/network/mixins/tcp.rb', line 54 parameter :local_port, :type => Integer, :description => 'TCP local port' |
- (Object) port
TCP port
46 47 |
# File 'lib/ronin/network/mixins/tcp.rb', line 46 parameter :port, :type => Integer, :description => 'TCP port' |
- (Object) port=(value)
TCP port
46 47 |
# File 'lib/ronin/network/mixins/tcp.rb', line 46 parameter :port, :type => Integer, :description => 'TCP port' |
- (Object) server_host
TCP server host
58 59 |
# File 'lib/ronin/network/mixins/tcp.rb', line 58 parameter :server_host, :type => String, :description => 'TCP server host' |
- (Object) server_host=(value)
TCP server host
58 59 |
# File 'lib/ronin/network/mixins/tcp.rb', line 58 parameter :server_host, :type => String, :description => 'TCP server host' |
- (Object) server_port
TCP server port
62 63 |
# File 'lib/ronin/network/mixins/tcp.rb', line 62 parameter :server_port, :type => Integer, :description => 'TCP server port' |
- (Object) server_port=(value)
TCP server port
62 63 |
# File 'lib/ronin/network/mixins/tcp.rb', line 62 parameter :server_port, :type => Integer, :description => 'TCP server port' |
- (nil) tcp_accept {|client| ... } (protected)
Creates a new temporary TCPServer object listening on
server_host and server_port parameters.
The TCPServer will accepting one client, pass the newly connected
client to a given block, disconnects the client and stops
listening.
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/ronin/network/mixins/tcp.rb', line 323 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]) client_port = client_addr[1] print_info "Client connected #{client_host}:#{client_port}" yield client if block_given? print_info "Disconnected client #{client_host}:#{client_port}" end print_info "Closed #{server_host_port}" return nil end |
- (String) tcp_banner {|banner| ... } (protected)
Connects to the host and port specified by the host and port
parameters, reads the banner then closes the connection.
200 201 202 203 204 |
# File 'lib/ronin/network/mixins/tcp.rb', line 200 def (&block) print_debug "Grabbing banner from #{host_port}" return super(self.host,self.port,self.local_host,self.local_port,&block) end |
- (TCPSocket) tcp_connect {|socket| ... } (protected)
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.
120 121 122 123 124 |
# File 'lib/ronin/network/mixins/tcp.rb', line 120 def tcp_connect(&block) print_info "Connecting to #{host_port} ..." return super(self.host,self.port,self.local_host,self.local_port,&block) end |
- (TCPSocket) tcp_connect_and_send(data) {|socket| ... } (protected)
Connects to the host and port specified by the host and port
parameters, then sends the given data.
146 147 148 149 150 151 |
# File 'lib/ronin/network/mixins/tcp.rb', line 146 def tcp_connect_and_send(data,&block) print_info "Connecting to #{host_port} ..." print_debug "Sending data: #{data.inspect}" return super(data,self.host,self.port,self.local_host,self.local_port,&block) end |
- (Boolean?) tcp_open?(timeout = nil) (protected)
Tests whether the TCP port, specified by the host and port
parameters, is open.
84 85 86 87 88 |
# File 'lib/ronin/network/mixins/tcp.rb', line 84 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 |
- (true) tcp_send(data) (protected)
Connects to the host and port specified by the host and port
parameters, sends the given data and then disconnects.
222 223 224 225 226 227 228 229 230 |
# File 'lib/ronin/network/mixins/tcp.rb', line 222 def tcp_send(data) print_info "Connecting to #{host_port} ..." print_debug "Sending data: #{data.inspect}" super(data,self.host,self.port,self.local_host,self.local_port) print_info "Disconnected from #{host_port}" return true end |
- (TCPServer) tcp_server {|server| ... } (protected)
Creates a new TCPServer object listening on the server_host
and server_port parameters.
252 253 254 255 256 |
# File 'lib/ronin/network/mixins/tcp.rb', line 252 def tcp_server(&block) print_info "Listening on #{self.server_host_port} ..." return super(self.server_port,self.server_host,&block) end |
- (nil) tcp_server_session {|server| ... } (protected)
Creates a new temporary TCPServer object listening on the
server_host and server_port parameters.
286 287 288 289 290 291 292 293 |
# File 'lib/ronin/network/mixins/tcp.rb', line 286 def tcp_server_session(&block) print_info "Listening on #{server_host_port} ..." super(self.server_port,self.server_host,&block) print_info "Closed #{server_host_port}" return nil end |
- (nil) tcp_session {|socket| ... } (protected)
Creates a TCP session to the host and port specified by the
host and port parameters.
170 171 172 173 174 175 176 177 |
# File 'lib/ronin/network/mixins/tcp.rb', line 170 def tcp_session(&block) print_info "Connecting to #{host_port} ..." super(self.host,self.port,self.local_host,self.local_port,&block) print_info "Disconnected from #{host_port}" return nil end |
- (Object) tcp_single_server(&block) (protected)
Deprecated as of 0.5.0. Use #tcp_accept instead.
346 347 348 |
# File 'lib/ronin/network/mixins/tcp.rb', line 346 def tcp_single_server(&block) tcp_accept(&block) end |