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
-
.host ⇒ Object
TCP host.
-
.host=(value) ⇒ Object
TCP host.
-
.local_host ⇒ Object
TCP local host.
-
.local_host=(value) ⇒ Object
TCP local host.
-
.local_port ⇒ Object
TCP local port.
-
.local_port=(value) ⇒ Object
TCP local port.
-
.port ⇒ Object
TCP port.
-
.port=(value) ⇒ Object
TCP port.
-
.server_host ⇒ Object
TCP server host.
-
.server_host=(value) ⇒ Object
TCP server host.
-
.server_port ⇒ Object
TCP server port.
-
.server_port=(value) ⇒ Object
TCP server port.
Instance Method Summary collapse
-
#host ⇒ Object
TCP host.
-
#host=(value) ⇒ Object
TCP host.
-
#local_host ⇒ Object
TCP local host.
-
#local_host=(value) ⇒ Object
TCP local host.
-
#local_port ⇒ Object
TCP local port.
-
#local_port=(value) ⇒ Object
TCP local port.
-
#port ⇒ Object
TCP port.
-
#port=(value) ⇒ Object
TCP port.
-
#server_host ⇒ Object
TCP server host.
-
#server_host=(value) ⇒ Object
TCP server host.
-
#server_port ⇒ Object
TCP server port.
-
#server_port=(value) ⇒ Object
TCP server port.
-
#tcp_accept {|client| ... } ⇒ nil
protected
Creates a new temporary TCPServer object listening on
server_host
andserver_port
parameters. -
#tcp_banner {|banner| ... } ⇒ String
protected
Connects to the host and port specified by the
host
andport
parameters, reads the banner then closes the connection. -
#tcp_connect {|socket| ... } ⇒ TCPSocket
protected
Opens a TCP connection to the host and port specified by the
host
andport
parameters. -
#tcp_connect_and_send(data) {|socket| ... } ⇒ TCPSocket
protected
Connects to the host and port specified by the
host
andport
parameters, then sends the given data. -
#tcp_open?(timeout = nil) ⇒ Boolean?
protected
Tests whether the TCP port, specified by the
host
andport
parameters, is open. -
#tcp_send(data) ⇒ true
protected
Connects to the host and port specified by the
host
andport
parameters, sends the given data and then disconnects. -
#tcp_server {|server| ... } ⇒ TCPServer
protected
Creates a new TCPServer object listening on the
server_host
andserver_port
parameters. -
#tcp_server_session {|server| ... } ⇒ nil
protected
Creates a new temporary TCPServer object listening on the
server_host
andserver_port
parameters. -
#tcp_session {|socket| ... } ⇒ nil
protected
Creates a TCP session to the host and port specified by the
host
andport
parameters. -
#tcp_single_server(&block) ⇒ Object
protected
deprecated
Deprecated.
Deprecated as of 0.5.0. Use #tcp_accept instead.
Methods included from Mixin
Methods included from TCP
Class Method Details
.host ⇒ Object
TCP host
42 43 |
# File 'lib/ronin/network/mixins/tcp.rb', line 42 parameter :host, :type => String, :description => 'TCP host' |
.host=(value) ⇒ Object
TCP host
42 43 |
# File 'lib/ronin/network/mixins/tcp.rb', line 42 parameter :host, :type => String, :description => 'TCP host' |
.local_host ⇒ Object
TCP local host
50 51 |
# File 'lib/ronin/network/mixins/tcp.rb', line 50 parameter :local_host, :type => String, :description => 'TCP local host' |
.local_host=(value) ⇒ Object
TCP local host
50 51 |
# File 'lib/ronin/network/mixins/tcp.rb', line 50 parameter :local_host, :type => String, :description => 'TCP local host' |
.local_port ⇒ Object
TCP local port
54 55 |
# File 'lib/ronin/network/mixins/tcp.rb', line 54 parameter :local_port, :type => Integer, :description => 'TCP local port' |
.local_port=(value) ⇒ Object
TCP local port
54 55 |
# File 'lib/ronin/network/mixins/tcp.rb', line 54 parameter :local_port, :type => Integer, :description => 'TCP local port' |
.port ⇒ Object
TCP port
46 47 |
# File 'lib/ronin/network/mixins/tcp.rb', line 46 parameter :port, :type => Integer, :description => 'TCP port' |
.port=(value) ⇒ Object
TCP port
46 47 |
# File 'lib/ronin/network/mixins/tcp.rb', line 46 parameter :port, :type => Integer, :description => 'TCP port' |
.server_host ⇒ Object
TCP server host
58 59 |
# File 'lib/ronin/network/mixins/tcp.rb', line 58 parameter :server_host, :type => String, :description => 'TCP server host' |
.server_host=(value) ⇒ Object
TCP server host
58 59 |
# File 'lib/ronin/network/mixins/tcp.rb', line 58 parameter :server_host, :type => String, :description => 'TCP server host' |
Instance Method Details
#host ⇒ Object
TCP host
42 43 |
# File 'lib/ronin/network/mixins/tcp.rb', line 42 parameter :host, :type => String, :description => 'TCP host' |
#host=(value) ⇒ Object
TCP host
42 43 |
# File 'lib/ronin/network/mixins/tcp.rb', line 42 parameter :host, :type => String, :description => 'TCP host' |
#local_host ⇒ Object
TCP local host
50 51 |
# File 'lib/ronin/network/mixins/tcp.rb', line 50 parameter :local_host, :type => String, :description => 'TCP local host' |
#local_host=(value) ⇒ Object
TCP local host
50 51 |
# File 'lib/ronin/network/mixins/tcp.rb', line 50 parameter :local_host, :type => String, :description => 'TCP local host' |
#local_port ⇒ Object
TCP local port
54 55 |
# File 'lib/ronin/network/mixins/tcp.rb', line 54 parameter :local_port, :type => Integer, :description => 'TCP local port' |
#local_port=(value) ⇒ Object
TCP local port
54 55 |
# File 'lib/ronin/network/mixins/tcp.rb', line 54 parameter :local_port, :type => Integer, :description => 'TCP local port' |
#port ⇒ Object
TCP port
46 47 |
# File 'lib/ronin/network/mixins/tcp.rb', line 46 parameter :port, :type => Integer, :description => 'TCP port' |
#port=(value) ⇒ Object
TCP port
46 47 |
# File 'lib/ronin/network/mixins/tcp.rb', line 46 parameter :port, :type => Integer, :description => 'TCP port' |
#server_host ⇒ Object
TCP server host
58 59 |
# File 'lib/ronin/network/mixins/tcp.rb', line 58 parameter :server_host, :type => String, :description => 'TCP server host' |
#server_host=(value) ⇒ Object
TCP server host
58 59 |
# File 'lib/ronin/network/mixins/tcp.rb', line 58 parameter :server_host, :type => String, :description => 'TCP server host' |
#server_port ⇒ Object
TCP server port
62 63 |
# File 'lib/ronin/network/mixins/tcp.rb', line 62 parameter :server_port, :type => Integer, :description => 'TCP server port' |
#server_port=(value) ⇒ Object
TCP server port
62 63 |
# File 'lib/ronin/network/mixins/tcp.rb', line 62 parameter :server_port, :type => Integer, :description => 'TCP server port' |
#tcp_accept {|client| ... } ⇒ nil (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 |
#tcp_banner {|banner| ... } ⇒ String (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 |
#tcp_connect {|socket| ... } ⇒ TCPSocket (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 |
#tcp_connect_and_send(data) {|socket| ... } ⇒ TCPSocket (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 |
#tcp_open?(timeout = nil) ⇒ Boolean? (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 |
#tcp_send(data) ⇒ true (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 |
#tcp_server {|server| ... } ⇒ TCPServer (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 |
#tcp_server_session {|server| ... } ⇒ nil (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 |
#tcp_session {|socket| ... } ⇒ nil (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 |
#tcp_single_server(&block) ⇒ Object (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 |